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 3, 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.top_block):
32 def __init__(self, options):
33 gr.top_block.__init__(self, "usrp_sounder_rx")
34 self._options = options
35 self._u = usrp_source_c(0,
36 self._options.rx_subdev_spec,
38 self._options.chip_rate,
41 self._options.verbose)
42 self._options.chip_rate = self._u._if_rate
43 self._length = 2**self._options.degree-1
44 self._receiver = sounder_rx(self._options.chip_rate,
46 self._options.verbose)
48 samples = 100 * self._length**2
50 head = gr.head(gr.sizeof_gr_complex, samples)
51 c2m = gr.complex_to_mag()
52 s2v = gr.stream_to_vector(gr.sizeof_float, self._length)
53 lpf = gr.single_pole_iir_filter_ff(self._options.alpha, self._length)
54 v2s = gr.vector_to_stream(gr.sizeof_float, self._length)
55 sink = gr.file_sink(gr.sizeof_float, "impulse.dat")
57 self.connect(self._u, head, self._receiver, c2m, s2v, lpf, v2s, sink)
59 if self._options.verbose:
60 print "Chip rate is", n2s(self._options.chip_rate), "chips/sec"
61 print "Resolution is", n2s(1.0/self._options.chip_rate), "sec"
62 print "Using PN code of degree", self._options.degree
65 parser = OptionParser(option_class=eng_option)
66 parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
67 help="select USRP Rx side A or B (default=first found)")
68 parser.add_option("-f", "--freq", type="eng_float", default=0.0,
69 help="set center frequency (default=%default)")
70 parser.add_option("-c", "--cal", type="eng_float", default=0.0,
71 help="set frequency calibration offset (default=%default)")
72 parser.add_option("-v", "--verbose", action="store_true", default=False,
73 help="print extra debugging info")
74 parser.add_option("-d", "--degree", type="int", default=10,
75 help="set PN code degree (length=2**degree-1, default=%default)")
76 parser.add_option("-r", "--chip-rate", type="eng_float", default=8e6,
77 help="set sounder chip rate (default=%default)")
78 parser.add_option("-g", "--gain", type="eng_float", default=None,
79 help="set receiver gain (default=%default)")
80 parser.add_option("", "--alpha", type="eng_float", default=1.0,
81 help="set smoothing constant (default=%default)")
82 (options, args) = parser.parse_args()
87 top_block = usrp_sounder_rx(options)
88 runtime = gr.runtime(top_block)
92 except KeyboardInterrupt:
95 if __name__ == '__main__':