summaryrefslogtreecommitdiff
path: root/gr-uhd/examples/python
diff options
context:
space:
mode:
Diffstat (limited to 'gr-uhd/examples/python')
-rwxr-xr-xgr-uhd/examples/python/fm_tx4.py2
-rwxr-xr-xgr-uhd/examples/python/max_power.py3
-rwxr-xr-xgr-uhd/examples/python/usrp_spectrum_sense.py41
-rwxr-xr-xgr-uhd/examples/python/usrp_tv_rcv.py8
-rwxr-xr-xgr-uhd/examples/python/usrp_tv_rcv_nogui.py12
5 files changed, 46 insertions, 20 deletions
diff --git a/gr-uhd/examples/python/fm_tx4.py b/gr-uhd/examples/python/fm_tx4.py
index e4cf3ded24..fefa67861b 100755
--- a/gr-uhd/examples/python/fm_tx4.py
+++ b/gr-uhd/examples/python/fm_tx4.py
@@ -56,7 +56,7 @@ class pipeline(gr.hier_block2):
gr.io_signature(1, 1, gr.sizeof_gr_complex))
try:
- src = gr.file_source (gr.sizeof_float, filename, True)
+ src = blocks.file_source (gr.sizeof_float, filename, True)
except RuntimeError:
sys.stderr.write(("\nError: Could not open file '%s'\n\n" % \
filename))
diff --git a/gr-uhd/examples/python/max_power.py b/gr-uhd/examples/python/max_power.py
index 79fe120641..e1504e5ea2 100755
--- a/gr-uhd/examples/python/max_power.py
+++ b/gr-uhd/examples/python/max_power.py
@@ -27,6 +27,7 @@ Setup USRP for maximum power consumption.
from gnuradio import gr
from gnuradio import analog
+from gnuradio import blocks
from gnuradio import uhd
from gnuradio.eng_option import eng_option
from optparse import OptionParser
@@ -95,7 +96,7 @@ class build_block(gr.top_block):
self.u_rx = uhd.usrp_source(device_addr=args,
io_type=uhd.io_type.COMPLEX_FLOAT32,
num_channels=rx_nchan)
- self.rx_dst0 = gr.null_sink(gr.sizeof_gr_complex)
+ self.rx_dst0 = blocks.null_sink(gr.sizeof_gr_complex)
self.u_rx.set_samp_rate(MAX_RATE)
diff --git a/gr-uhd/examples/python/usrp_spectrum_sense.py b/gr-uhd/examples/python/usrp_spectrum_sense.py
index 39e85ab18a..fe97e21cbd 100755
--- a/gr-uhd/examples/python/usrp_spectrum_sense.py
+++ b/gr-uhd/examples/python/usrp_spectrum_sense.py
@@ -107,7 +107,10 @@ class my_top_block(gr.top_block):
help="time to delay (in seconds) after changing frequency [default=%default]")
parser.add_option("", "--dwell-delay", type="eng_float",
default=10e-3, metavar="SECS",
- help="time to dwell (in seconds) at a given frequncy [default=%default]")
+ help="time to dwell (in seconds) at a given frequency [default=%default]")
+ parser.add_option("", "--channel-bandwidth", type="eng_float",
+ default=12.5e3, metavar="Hz",
+ help="channel bandwidth of fft bins in Hz [default=%default]")
parser.add_option("-F", "--fft-size", type="int", default=256,
help="specify number of FFT bins [default=%default]")
parser.add_option("", "--real-time", action="store_true", default=False,
@@ -125,8 +128,9 @@ class my_top_block(gr.top_block):
# swap them
self.min_freq, self.max_freq = self.max_freq, self.min_freq
- self.fft_size = options.fft_size
-
+ self.fft_size = options.fft_size
+ self.channel_bandwidth = options.channel_bandwidth
+
if not options.real_time:
realtime = False
else:
@@ -150,14 +154,14 @@ class my_top_block(gr.top_block):
if(options.antenna):
self.u.set_antenna(options.antenna, 0)
- usrp_rate = options.samp_rate
+ self.usrp_rate = usrp_rate = options.samp_rate
self.u.set_samp_rate(usrp_rate)
dev_rate = self.u.get_samp_rate()
- s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)
+ s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)
mywindow = filter.window.blackmanharris(self.fft_size)
- ffter = fft.fft_vcc(self.fft_size, True, mywindow)
+ ffter = fft.fft_vcc(self.fft_size, True, mywindow, True)
power = 0
for tap in mywindow:
power += tap*tap
@@ -197,7 +201,7 @@ class my_top_block(gr.top_block):
options.gain = float(g.start()+g.stop())/2.0
self.set_gain(options.gain)
- print "gain =", options.gain
+ print "gain =", options.gain
def set_next_freq(self):
target_freq = self.next_freq
@@ -231,6 +235,20 @@ class my_top_block(gr.top_block):
def main_loop(tb):
+
+ def nearest_freq(freq, channel_bandwidth):
+ freq = round(freq / channel_bandwidth, 0) * channel_bandwidth
+ return freq
+
+ def bin_freq(i_bin, center_freq):
+ hz_per_bin = tb.usrp_rate / tb.fft_size
+ freq = center_freq - (tb.usrp_rate / 2) + (hz_per_bin * i_bin)
+ freq = nearest_freq(freq, tb.channel_bandwidth)
+ return freq
+
+ bin_start = int(tb.fft_size * ((1 - 0.75) / 2))
+ bin_stop = int(tb.fft_size - bin_start)
+
while 1:
# Get the next message sent from the C++ code (blocking call).
@@ -238,7 +256,7 @@ def main_loop(tb):
m = parse_msg(tb.msgq.delete_head())
# Print center freq so we know that something is happening...
- print m.center_freq
+ #print "m.center_freq:", m.center_freq
# FIXME do something useful with the data...
@@ -248,6 +266,13 @@ def main_loop(tb):
# m.raw_data is a string that contains the binary floats.
# You could write this as binary to a file.
+ for i_bin in range(bin_start, bin_stop):
+
+ # create signal object to find matching signals
+ freq = int(bin_freq(i_bin, m.center_freq))
+ power = float(m.data[i_bin])
+
+ print freq, power
if __name__ == '__main__':
t = ThreadClass()
diff --git a/gr-uhd/examples/python/usrp_tv_rcv.py b/gr-uhd/examples/python/usrp_tv_rcv.py
index 3e612f6a02..301840f41d 100755
--- a/gr-uhd/examples/python/usrp_tv_rcv.py
+++ b/gr-uhd/examples/python/usrp_tv_rcv.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2005-2007,2011,2012 Free Software Foundation, Inc.
+# Copyright 2005-2007,2011-2013 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -124,7 +124,7 @@ class tv_rx_block (stdgui2.std_top_block):
if not ((filename is None) or (filename=="usrp")):
# file is data source
- self.filesource = gr.file_source(gr.sizeof_short,filename,options.repeat)
+ self.filesource = blocks.file_source(gr.sizeof_short,filename,options.repeat)
self.istoc = blocks.interleaved_short_to_complex()
self.connect(self.filesource,self.istoc)
self.src=self.istoc
@@ -193,7 +193,7 @@ class tv_rx_block (stdgui2.std_top_block):
+ " gray:" + options.out_filename
print "(Use the spacebar to advance to next frames)"
options.repeat=False
- file_sink=gr.file_sink(gr.sizeof_char, options.out_filename)
+ file_sink = blocks.file_sink(gr.sizeof_char, options.out_filename)
self.dst =file_sink
self.agc = analog.agc_cc(1e-7,1.0,1.0) #1e-7
@@ -226,7 +226,7 @@ class tv_rx_block (stdgui2.std_top_block):
elif process_type=='do_nullsink':
#self.connect (self.src, self.am_demod,self.invert_and_scale,f2uc,video_sink)
c2r=blocks.complex_to_real()
- nullsink=gr.null_sink(gr.sizeof_float)
+ nullsink=blocks.null_sink(gr.sizeof_float)
self.connect (self.src, c2r,nullsink) #video_sink)
elif process_type=='do_tv_sync_corr':
frame_size=width*height #int(usrp_rate/25.0)
diff --git a/gr-uhd/examples/python/usrp_tv_rcv_nogui.py b/gr-uhd/examples/python/usrp_tv_rcv_nogui.py
index 5eef4a00f6..80e2e1c17a 100755
--- a/gr-uhd/examples/python/usrp_tv_rcv_nogui.py
+++ b/gr-uhd/examples/python/usrp_tv_rcv_nogui.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2005-2007,2011 Free Software Foundation, Inc.
+# Copyright 2005-2007,2011,2013 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -120,9 +120,9 @@ class my_top_block(gr.top_block):
if not (options.in_filename=="usrp"):
# file is data source, capture with usr_rx_csfile.py
- self.filesource = gr.file_source(gr.sizeof_short,
- options.in_filename,
- options.repeat)
+ self.filesource = blocks.file_source(gr.sizeof_short,
+ options.in_filename,
+ options.repeat)
self.istoc = blocks.interleaved_short_to_complex()
self.connect(self.filesource,self.istoc)
self.src=self.istoc
@@ -196,13 +196,13 @@ class my_top_block(gr.top_block):
print "use the following line to show the demodulated TV-signal:"
print "display -depth 8 -size " +str(width)+ "x" + str(height) + " gray:" +filename
print "(Use the spacebar to advance to next frames)"
- file_sink=gr.file_sink(gr.sizeof_char, filename)
+ file_sink = blocks.file_sink(gr.sizeof_char, filename)
self.dst =file_sink
if options.nframes is None:
self.connect(self.src, self.agc)
else:
- self.head = gr.head(gr.sizeof_gr_complex, int(options.nframes*width*height))
+ self.head = blocks.head(gr.sizeof_gr_complex, int(options.nframes*width*height))
self.connect(self.src, self.head, self.agc)
self.connect (self.agc, self.am_demod, self.invert_and_scale,