diff options
author | jcorgan | 2007-06-05 04:21:29 +0000 |
---|---|---|
committer | jcorgan | 2007-06-05 04:21:29 +0000 |
commit | e283fe844c88aa33b6bde4a7cb74f0d1c2ddbbc5 (patch) | |
tree | 0081a8487d3a4bb7a65404c2662d0a7480f50421 /gr-sounder/src/python | |
parent | 389906ea28957c6d7a08b5cd43a4ac2ab0c9d24d (diff) | |
download | gnuradio-e283fe844c88aa33b6bde4a7cb74f0d1c2ddbbc5.tar.gz gnuradio-e283fe844c88aa33b6bde4a7cb74f0d1c2ddbbc5.tar.bz2 gnuradio-e283fe844c88aa33b6bde4a7cb74f0d1c2ddbbc5.zip |
Merged r5566:5676 from jcorgan/snd into trunk, with minor changes. Component gr-sounder is now complete for recording impulse responses to a file.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5679 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gr-sounder/src/python')
-rw-r--r-- | gr-sounder/src/python/sounder.py | 40 | ||||
-rwxr-xr-x | gr-sounder/src/python/usrp_sounder.py | 15 |
2 files changed, 46 insertions, 9 deletions
diff --git a/gr-sounder/src/python/sounder.py b/gr-sounder/src/python/sounder.py index b3c5423c4..ce00e964d 100644 --- a/gr-sounder/src/python/sounder.py +++ b/gr-sounder/src/python/sounder.py @@ -32,6 +32,7 @@ bmFR_MODE_RX = 1 << 2 # bit 2: enable receiver bmFR_MODE_LP = 1 << 3 # bit 3: enable digital loopback FR_DEGREE = usrp.FR_USER_1 +FR_AMPL = usrp.FR_USER_2 def pick_subdevice(u): """ @@ -47,15 +48,18 @@ def pick_subdevice(u): return (0, 0) class sounder_tx: - def __init__(self, loopback=False,verbose=False): + def __init__(self, loopback=False,ampl=4096,verbose=False,debug=False): self._loopback=loopback + self._amplitude = ampl self._verbose = verbose + self._debug = debug self._u = usrp.sink_s(fpga_filename='usrp_sounder.rbf') if not self._loopback: self._subdev_spec = usrp.pick_tx_subdevice(self._u) self._subdev = usrp.selected_subdev(self._u, self._subdev_spec) if self._verbose: print "Using", self._subdev.name(), "for sounder transmitter." + self.set_amplitude(ampl) self._u.start() def tune(self, frequency): @@ -65,9 +69,16 @@ class sounder_tx: if result == False: raise RuntimeError("Failed to set transmitter frequency.") + def set_amplitude(self, ampl): + self._amplitude = ampl + if self._debug: + print "Writing amplitude register with:", hex(self._mode) + self._u._write_fpga_reg(FR_AMPL, self._amplitude) + class sounder_rx: - def __init__(self,subdev_spec=None,length=1,msgq=None,loopback=False,verbose=False,debug=False): + def __init__(self,subdev_spec=None,gain=None,length=1,msgq=None,loopback=False,verbose=False,debug=False): self._subdev_spec = subdev_spec + self._gain = gain self._length = length self._msgq = msgq self._loopback = loopback @@ -84,6 +95,7 @@ class sounder_rx: if self._verbose: print "Using", self._subdev.name(), "for sounder receiver." + self.set_gain(self._gain) self._vblen = gr.sizeof_gr_complex*self._length if self._debug: print "Generating impulse vectors of length", self._length, "byte length", self._vblen @@ -99,6 +111,19 @@ class sounder_rx: if result == False: raise RuntimeError("Failed to set receiver frequency.") + def set_gain(self, gain): + self._gain = gain + if self._loopback: + return + + if self._gain is None: + # if no gain was specified, use the mid-point in dB + g = self._subdev.gain_range() + self._gain = float(g[0]+g[1])/2 + if self._verbose: + print "Setting receiver gain to", gain + self._subdev.set_gain(self._gain) + def start(self): if self._debug: print "Starting receiver flow graph." @@ -119,13 +144,15 @@ class sounder_rx: class sounder: - def __init__(self,transmit=False,receive=False,loopback=False,rx_subdev_spec=None, - frequency=0.0,degree=10,length=1,msgq=None,verbose=False,debug=False): + def __init__(self,transmit=False,receive=False,loopback=False,rx_subdev_spec=None,ampl=0x1FFF, + frequency=0.0,rx_gain=None,degree=12,length=1,msgq=None,verbose=False,debug=False): self._transmit = transmit self._receive = receive self._loopback = loopback self._rx_subdev_spec = rx_subdev_spec self._frequency = frequency + self._amplitude = ampl + self._rx_gain = rx_gain self._degree = degree self._length = length self._msgq = msgq @@ -139,11 +166,12 @@ class sounder: self._receiving = False if self._transmit: - self._trans = sounder_tx(loopback=self._loopback,verbose=self._verbose) + self._trans = sounder_tx(loopback=self._loopback,ampl=self._amplitude, + verbose=self._verbose) self._u = self._trans._u if self._receive: - self._rcvr = sounder_rx(subdev_spec=self._rx_subdev_spec,length=self._length, + self._rcvr = sounder_rx(subdev_spec=self._rx_subdev_spec,length=self._length,gain=self._rx_gain, msgq=self._msgq,loopback=self._loopback,verbose=self._verbose, debug=self._debug) self._u = self._rcvr._u # either receiver or transmitter object will do diff --git a/gr-sounder/src/python/usrp_sounder.py b/gr-sounder/src/python/usrp_sounder.py index 4aada45d6..20f187114 100755 --- a/gr-sounder/src/python/usrp_sounder.py +++ b/gr-sounder/src/python/usrp_sounder.py @@ -25,6 +25,7 @@ from gnuradio.sounder import sounder from gnuradio import eng_notation from gnuradio.eng_option import eng_option from optparse import OptionParser +import numpy import sys n2s = eng_notation.num_to_str @@ -33,10 +34,14 @@ def main(): parser = OptionParser(option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0), help="select USRP Rx side A or B") + parser.add_option("-g", "--gain", type="eng_float", default=None, + help="set gain in dB (default is midpoint)") parser.add_option("-f", "--frequency", type="eng_float", default=0.0, help="set frequency to FREQ in Hz, default is %default", metavar="FREQ") parser.add_option("-d", "--degree", type="int", default=12, help="set sounding sequence degree (2-12), default is %default,") + parser.add_option("-a", "--amplitude", type="int", default=4096, + help="set waveform amplitude, default is %default,") parser.add_option("-t", "--transmit", action="store_true", default=False, help="enable sounding transmitter") parser.add_option("-r", "--receive", action="store_true", default=False, @@ -74,8 +79,9 @@ def main(): msgq = gr.msg_queue() s = sounder(transmit=options.transmit,receive=options.receive,loopback=options.loopback, - rx_subdev_spec=options.rx_subdev_spec,frequency=options.frequency,degree=options.degree, - length=length,msgq=msgq,verbose=options.verbose,debug=options.debug) + rx_subdev_spec=options.rx_subdev_spec,frequency=options.frequency,rx_gain=options.gain, + degree=options.degree,length=length,msgq=msgq,verbose=options.verbose,ampl=options.amplitude, + debug=options.debug) s.start() if options.receive: @@ -89,7 +95,10 @@ def main(): rec = msg.to_string()[:length*gr.sizeof_gr_complex] if options.debug: print "Received impulse vector of length", len(rec) - f.write(rec) + recarray = numpy.fromstring(rec, dtype=numpy.complex64) + imparray = recarray[::-1] + data = imparray.tostring() + f.write(data) except KeyboardInterrupt: pass |