3 # Copyright 2007 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
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)
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.
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., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
23 from gnuradio import gr, eng_notation
24 from gnuradio.eng_option import eng_option
25 from optparse import OptionParser
26 from usrp_source import usrp_source_c
27 from sounder_rx import sounder_rx
29 n2s = eng_notation.num_to_str
31 class usrp_sounder_rx(gr.hier_block2):
32 def __init__(self, options):
33 gr.hier_block2.__init__(self, "usrp_sounder_rx",
34 gr.io_signature(0,0,0),
35 gr.io_signature(0,0,0))
37 self._options = options
38 self._u = usrp_source_c(0,
39 self._options.rx_subdev_spec,
41 self._options.chip_rate,
44 self._options.verbose)
45 self._options.chip_rate = self._u._if_rate
46 self._length = 2**self._options.degree-1
47 self._receiver = sounder_rx(self._options.chip_rate,
49 self._options.verbose)
51 samples = 100 * self._length**2
53 self.define_component("usrp", self._u)
54 self.define_component("head", gr.head(gr.sizeof_gr_complex, samples))
55 self.define_component("rx", self._receiver)
56 self.define_component("c2m", gr.complex_to_mag())
57 self.define_component("s2v", gr.stream_to_vector(gr.sizeof_float, self._length))
58 self.define_component("lpf", gr.single_pole_iir_filter_ff(self._options.alpha, self._length))
59 self.define_component("v2s", gr.vector_to_stream(gr.sizeof_float, self._length))
60 self.define_component("sink", gr.file_sink(gr.sizeof_float, "impulse.dat"))
62 self.connect("usrp", 0, "head", 0)
63 self.connect("head", 0, "rx", 0)
64 self.connect("rx", 0, "c2m", 0)
65 self.connect("c2m", 0, "s2v", 0)
66 self.connect("s2v", 0, "lpf", 0)
67 self.connect("lpf", 0, "v2s", 0)
68 self.connect("v2s", 0, "sink", 0)
70 if self._options.verbose:
71 print "Chip rate is", n2s(self._options.chip_rate), "chips/sec"
72 print "Resolution is", n2s(1.0/self._options.chip_rate), "sec"
73 print "Using PN code of degree", self._options.degree
76 parser = OptionParser(option_class=eng_option)
77 parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
78 help="select USRP Rx side A or B (default=first found)")
79 parser.add_option("-f", "--freq", type="eng_float", default=0.0,
80 help="set center frequency (default=%default)")
81 parser.add_option("-c", "--cal", type="eng_float", default=0.0,
82 help="set frequency calibration offset (default=%default)")
83 parser.add_option("-v", "--verbose", action="store_true", default=False,
84 help="print extra debugging info")
85 parser.add_option("-d", "--degree", type="int", default=10,
86 help="set PN code degree (length=2**degree-1, default=%default)")
87 parser.add_option("-r", "--chip-rate", type="eng_float", default=8e6,
88 help="set sounder chip rate (default=%default)")
89 parser.add_option("-g", "--gain", type="eng_float", default=None,
90 help="set receiver gain (default=%default)")
91 parser.add_option("", "--alpha", type="eng_float", default=1.0,
92 help="set smoothing constant (default=%default)")
93 (options, args) = parser.parse_args()
98 top_block = usrp_sounder_rx(options)
99 runtime = gr.runtime(top_block)
103 except KeyboardInterrupt:
106 if __name__ == '__main__':