From 54d6b9281dc233e0b2acf26884073d973b7663de Mon Sep 17 00:00:00 2001 From: jcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5> Date: Tue, 4 Sep 2007 02:43:56 +0000 Subject: Merged r6271:6278 from jcorgan/t182 into trunk. Implements ticket:182. Created new top-level component, gr-utils, to hold commonly used utility scripts (originally in gnuradio-examples). These now install into the system path, allowing their use from wherever. Reorganization of gnuradio-examples component: * Commonly used utility scripts moved from python/usrp into gr-utils. * Examples now install into $(prefix)/share/gnuradio/examples/... * Channel coding examples moved into gr-trellis/src/examples, now install from there, only if gr-atsc itself is going to built and installed. * ATSC example scripts now install into example hierarchy * Cruft has been moved into 'limbo' in repository, do not get installed Trunk passes 'make distcheck'. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6279 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-examples/python/Makefile.am | 24 +- .../python/apps/hf_explorer/Makefile.am | 4 + gnuradio-examples/python/apps/hf_radio/Makefile.am | 4 + gnuradio-examples/python/audio/Makefile.am | 7 +- gnuradio-examples/python/audio/dial_squelch.py | 89 ------- gnuradio-examples/python/audio/dialtone_v.py | 71 ------ .../python/channel-coding/Makefile.am | 41 ---- gnuradio-examples/python/channel-coding/README | 53 ----- .../python/channel-coding/fsm_files/Makefile.am | 37 --- .../channel-coding/fsm_files/awgn1o2_128.fsm | 265 --------------------- .../python/channel-coding/fsm_files/awgn1o2_16.fsm | 39 --- .../python/channel-coding/fsm_files/awgn1o2_4.fsm | 14 -- .../python/channel-coding/fsm_files/awgn1o2_8.fsm | 24 -- .../python/channel-coding/fsm_files/awgn2o3_16.fsm | 40 ---- .../python/channel-coding/fsm_files/awgn2o3_4.fsm | 15 -- .../channel-coding/fsm_files/awgn2o3_4_msb.fsm | 46 ---- .../channel-coding/fsm_files/awgn2o3_4_msbG.fsm | 60 ----- .../python/channel-coding/fsm_files/awgn2o3_8.fsm | 25 -- .../python/channel-coding/fsm_files/awgn2o4_4.fsm | 36 --- .../channel-coding/fsm_files/disconnected.fsm | 11 - .../python/channel-coding/fsm_files/irregular.fsm | 11 - .../python/channel-coding/fsm_files/rep3.fsm | 8 - .../python/channel-coding/fsm_files/rep5.fsm | 7 - .../python/channel-coding/fsm_files/simple.fsm | 13 - .../python/channel-coding/fsm_utils.py | 213 ----------------- .../python/channel-coding/test_sccc_hard.py | 101 -------- .../python/channel-coding/test_sccc_soft.py | 108 --------- .../python/channel-coding/test_sccc_turbo.py | 143 ----------- .../python/channel-coding/test_tcm.py | 118 --------- .../python/channel-coding/test_tcm1.py | 121 ---------- .../python/channel-coding/test_tcm2.py | 116 --------- .../python/channel-coding/test_tcm_combined.py | 100 -------- .../python/channel-coding/test_tcm_parallel.py | 106 --------- .../channel-coding/test_turbo_equalization.py | 143 ----------- .../channel-coding/test_turbo_equalization1.py | 147 ------------ .../channel-coding/test_turbo_equalization2.py | 147 ------------ .../channel-coding/test_viterbi_equalization.py | 94 -------- .../channel-coding/test_viterbi_equalization1.py | 103 -------- gnuradio-examples/python/digital/Makefile.am | 5 + gnuradio-examples/python/digital_voice/Makefile.am | 5 + gnuradio-examples/python/multi-antenna/Makefile.am | 5 + gnuradio-examples/python/multi_usrp/Makefile.am | 12 +- gnuradio-examples/python/ofdm/Makefile.am | 5 + gnuradio-examples/python/usrp/Makefile.am | 23 +- gnuradio-examples/python/usrp/am_rcv.py | 115 --------- gnuradio-examples/python/usrp/ayfabtu.dat | Bin 544640 -> 0 bytes gnuradio-examples/python/usrp/ayfabtu.py | 169 ------------- gnuradio-examples/python/usrp/benchmark_usb.py | 106 --------- gnuradio-examples/python/usrp/flexrf_debug.py | 169 ------------- gnuradio-examples/python/usrp/flexrf_siggen.py | 148 ------------ gnuradio-examples/python/usrp/limbo/am_rcv.py | 115 +++++++++ gnuradio-examples/python/usrp/limbo/ayfabtu.dat | Bin 0 -> 544640 bytes gnuradio-examples/python/usrp/limbo/ayfabtu.py | 169 +++++++++++++ .../python/usrp/limbo/flexrf_debug.py | 169 +++++++++++++ .../python/usrp/limbo/flexrf_siggen.py | 148 ++++++++++++ gnuradio-examples/python/usrp/limbo/siggen_min2.py | 62 +++++ .../python/usrp/limbo/test_dft_analysis.py | 72 ++++++ .../python/usrp/limbo/test_dft_synth.py | 79 ++++++ .../python/usrp/limbo/tvrx_am_rcv_gui.py | 154 ++++++++++++ .../python/usrp/limbo/usrp_fft_old.py | 110 +++++++++ gnuradio-examples/python/usrp/siggen_min2.py | 62 ----- gnuradio-examples/python/usrp/test_counting.py | 53 ----- gnuradio-examples/python/usrp/test_dft_analysis.py | 72 ------ gnuradio-examples/python/usrp/test_dft_synth.py | 79 ------ .../python/usrp/test_digital_loopback_counting.py | 65 ----- .../python/usrp/test_digital_loopback_lfsr.py | 62 ----- gnuradio-examples/python/usrp/tvrx_am_rcv_gui.py | 154 ------------ gnuradio-examples/python/usrp/usrp_fft.py | 254 -------------------- gnuradio-examples/python/usrp/usrp_fft_old.py | 110 --------- gnuradio-examples/python/usrp/usrp_oscope.py | 252 -------------------- gnuradio-examples/python/usrp/usrp_rx_cfile.py | 107 --------- gnuradio-examples/python/usrp/usrp_rx_nogui.py | 186 --------------- gnuradio-examples/python/usrp/usrp_siggen.py | 180 -------------- 73 files changed, 1145 insertions(+), 5035 deletions(-) delete mode 100755 gnuradio-examples/python/audio/dial_squelch.py delete mode 100755 gnuradio-examples/python/audio/dialtone_v.py delete mode 100644 gnuradio-examples/python/channel-coding/Makefile.am delete mode 100644 gnuradio-examples/python/channel-coding/README delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/Makefile.am delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_128.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_16.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_4.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_8.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_16.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_4.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_4_msb.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_4_msbG.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_8.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/awgn2o4_4.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/disconnected.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/irregular.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/rep3.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/rep5.fsm delete mode 100644 gnuradio-examples/python/channel-coding/fsm_files/simple.fsm delete mode 100755 gnuradio-examples/python/channel-coding/fsm_utils.py delete mode 100755 gnuradio-examples/python/channel-coding/test_sccc_hard.py delete mode 100755 gnuradio-examples/python/channel-coding/test_sccc_soft.py delete mode 100755 gnuradio-examples/python/channel-coding/test_sccc_turbo.py delete mode 100755 gnuradio-examples/python/channel-coding/test_tcm.py delete mode 100755 gnuradio-examples/python/channel-coding/test_tcm1.py delete mode 100755 gnuradio-examples/python/channel-coding/test_tcm2.py delete mode 100755 gnuradio-examples/python/channel-coding/test_tcm_combined.py delete mode 100755 gnuradio-examples/python/channel-coding/test_tcm_parallel.py delete mode 100755 gnuradio-examples/python/channel-coding/test_turbo_equalization.py delete mode 100755 gnuradio-examples/python/channel-coding/test_turbo_equalization1.py delete mode 100755 gnuradio-examples/python/channel-coding/test_turbo_equalization2.py delete mode 100755 gnuradio-examples/python/channel-coding/test_viterbi_equalization.py delete mode 100755 gnuradio-examples/python/channel-coding/test_viterbi_equalization1.py delete mode 100755 gnuradio-examples/python/usrp/am_rcv.py delete mode 100644 gnuradio-examples/python/usrp/ayfabtu.dat delete mode 100755 gnuradio-examples/python/usrp/ayfabtu.py delete mode 100755 gnuradio-examples/python/usrp/benchmark_usb.py delete mode 100755 gnuradio-examples/python/usrp/flexrf_debug.py delete mode 100755 gnuradio-examples/python/usrp/flexrf_siggen.py create mode 100755 gnuradio-examples/python/usrp/limbo/am_rcv.py create mode 100644 gnuradio-examples/python/usrp/limbo/ayfabtu.dat create mode 100755 gnuradio-examples/python/usrp/limbo/ayfabtu.py create mode 100755 gnuradio-examples/python/usrp/limbo/flexrf_debug.py create mode 100755 gnuradio-examples/python/usrp/limbo/flexrf_siggen.py create mode 100755 gnuradio-examples/python/usrp/limbo/siggen_min2.py create mode 100755 gnuradio-examples/python/usrp/limbo/test_dft_analysis.py create mode 100755 gnuradio-examples/python/usrp/limbo/test_dft_synth.py create mode 100755 gnuradio-examples/python/usrp/limbo/tvrx_am_rcv_gui.py create mode 100755 gnuradio-examples/python/usrp/limbo/usrp_fft_old.py delete mode 100755 gnuradio-examples/python/usrp/siggen_min2.py delete mode 100755 gnuradio-examples/python/usrp/test_counting.py delete mode 100755 gnuradio-examples/python/usrp/test_dft_analysis.py delete mode 100755 gnuradio-examples/python/usrp/test_dft_synth.py delete mode 100755 gnuradio-examples/python/usrp/test_digital_loopback_counting.py delete mode 100755 gnuradio-examples/python/usrp/test_digital_loopback_lfsr.py delete mode 100755 gnuradio-examples/python/usrp/tvrx_am_rcv_gui.py delete mode 100755 gnuradio-examples/python/usrp/usrp_fft.py delete mode 100755 gnuradio-examples/python/usrp/usrp_fft_old.py delete mode 100755 gnuradio-examples/python/usrp/usrp_oscope.py delete mode 100755 gnuradio-examples/python/usrp/usrp_rx_cfile.py delete mode 100755 gnuradio-examples/python/usrp/usrp_rx_nogui.py delete mode 100755 gnuradio-examples/python/usrp/usrp_siggen.py (limited to 'gnuradio-examples/python') diff --git a/gnuradio-examples/python/Makefile.am b/gnuradio-examples/python/Makefile.am index de576770f9..c9db48d6ab 100644 --- a/gnuradio-examples/python/Makefile.am +++ b/gnuradio-examples/python/Makefile.am @@ -19,5 +19,25 @@ # Boston, MA 02110-1301, USA. # -SUBDIRS = apps audio channel-coding digital_voice digital multi-antenna \ - multi_usrp networking usrp hier ofdm +include $(top_srcdir)/Makefile.common + +SUBDIRS = \ + apps \ + audio \ + digital_voice \ + digital \ + multi-antenna \ + multi_usrp \ + networking \ + usrp \ + hier \ + ofdm + +# Make example scripts with #! executable +install-data-local: + for i in `find $(exampledir) -type f ! -perm 755`; do \ + if head -1 $$i | grep -q '^#!'; then \ + chmod 755 $$i; \ + echo "made executable: $$i"; \ + fi; \ + done diff --git a/gnuradio-examples/python/apps/hf_explorer/Makefile.am b/gnuradio-examples/python/apps/hf_explorer/Makefile.am index 49aac10150..deb6c32d81 100644 --- a/gnuradio-examples/python/apps/hf_explorer/Makefile.am +++ b/gnuradio-examples/python/apps/hf_explorer/Makefile.am @@ -19,8 +19,12 @@ # Boston, MA 02110-1301, USA. # +include $(top_srcdir)/Makefile.common + EXTRA_DIST = \ README \ hfx2.py \ hfx_help +ourdatadir = $(exampledir)/hf_explorer +ourdata_DATA = $(EXTRA_DIST) \ No newline at end of file diff --git a/gnuradio-examples/python/apps/hf_radio/Makefile.am b/gnuradio-examples/python/apps/hf_radio/Makefile.am index 3f7340efe9..a6a4dfe3d3 100644 --- a/gnuradio-examples/python/apps/hf_radio/Makefile.am +++ b/gnuradio-examples/python/apps/hf_radio/Makefile.am @@ -19,6 +19,8 @@ # Boston, MA 02110-1301, USA. # +include $(top_srcdir)/Makefile.common + EXTRA_DIST = \ hfir.sci \ input.py \ @@ -32,3 +34,5 @@ EXTRA_DIST = \ startup.py \ ui.py +ourdatadir = $(exampledir)/hf_radio +ourdata_DATA = $(EXTRA_DIST) diff --git a/gnuradio-examples/python/audio/Makefile.am b/gnuradio-examples/python/audio/Makefile.am index e0fdb7e783..6c69588ca0 100644 --- a/gnuradio-examples/python/audio/Makefile.am +++ b/gnuradio-examples/python/audio/Makefile.am @@ -19,16 +19,19 @@ # Boston, MA 02110-1301, USA. # +include $(top_srcdir)/Makefile.common + EXTRA_DIST = \ audio_copy.py \ audio_fft.py \ audio_play.py \ audio_to_file.py \ - dial_squelch.py \ dial_tone.py \ - dialtone_v.py \ mono_tone.py \ multi_tone.py \ noise.py \ spectrum_inversion.py \ test_resampler.py + +ourdatadir = $(exampledir)/audio +ourdata_DATA = $(EXTRA_DIST) diff --git a/gnuradio-examples/python/audio/dial_squelch.py b/gnuradio-examples/python/audio/dial_squelch.py deleted file mode 100755 index 8a0c3f5626..0000000000 --- a/gnuradio-examples/python/audio/dial_squelch.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2006 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from gnuradio import gr, audio, eng_option -from gnuradio.eng_option import eng_option -from math import pi, cos -from optparse import OptionParser - -""" -This script generates a standard dial tone and then applies a sinusoidal -envelope to vary it's loudness. The audio is then passed through the -power squelch block before it gets sent to the sound card. By varying -the command line parameters, one can see the effect of differing -amounts of power averaging, threshold, and attack/decay ramping. -""" - -class app_flow_graph(gr.flow_graph): - def __init__(self, options, args): - gr.flow_graph.__init__(self) - - # Create dial tone by adding two sine waves - SRC1 = gr.sig_source_f(options.rate, gr.GR_SIN_WAVE, 350, 0.5, 0.0) - SRC2 = gr.sig_source_f(options.rate, gr.GR_SIN_WAVE, 440, 0.5, 0.0) - ADD = gr.add_ff() - - # Convert to vector stream (and back) to apply raised cosine envelope - # You could also do this with a vector_source_f block that repeats. - S2V = gr.stream_to_vector(gr.sizeof_float, options.rate) - ENV = [0.5-cos(2*pi*x/options.rate)/2 for x in range(options.rate)] - MLT = gr.multiply_const_vff(ENV) - V2S = gr.vector_to_stream(gr.sizeof_float, options.rate) - - # Run through power squelch with user supplied or default options - # Zero output when squelch is invoked - SQL = gr.pwr_squelch_ff(options.threshold, options.alpha, options.ramp, False) - DST = audio.sink(options.rate) - - # Solder it all together - self.connect(SRC1, (ADD, 0)) - self.connect(SRC2, (ADD, 1)) - self.connect(ADD, S2V, MLT, V2S, SQL, DST) - -def main(): - parser = OptionParser(option_class=eng_option) - parser.add_option("-r", "--rate", type="int", default=8000, help="set audio output sample rate to RATE", metavar="RATE") - parser.add_option("-t", "--threshold", type="eng_float", default=-10.0, help="set power squelch to DB", metavar="DB") - parser.add_option("-a", "--alpha", type="eng_float", default=None, help="set alpha to ALPHA", metavar="ALPHA") - parser.add_option("-m", "--ramp", type="int", default=None, help="set attack/decay ramp to SAMPLES", metavar="SAMPLES") - (options, args) = parser.parse_args() - - if options.alpha == None: - options.alpha = 50.0/options.rate - - if options.ramp == None: - options.ramp = options.rate/50 # ~ 20 ms - - print "Using audio rate of", options.rate - print "Using threshold of", options.threshold, "db" - print "Using alpha of", options.alpha - print "Using ramp of", options.ramp, "samples" - - fg = app_flow_graph(options, args) - - try: - fg.run() - except KeyboardInterrupt: - pass - -if __name__ == "__main__": - main() diff --git a/gnuradio-examples/python/audio/dialtone_v.py b/gnuradio-examples/python/audio/dialtone_v.py deleted file mode 100755 index ab1ca2a641..0000000000 --- a/gnuradio-examples/python/audio/dialtone_v.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2006 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from gnuradio import gr, audio -from math import pi, sin - -""" -This test script demonstrates the use of element-wise vector processing -vs. stream processing. The example is artificial in that the stream -version in dial_tone.py is the normal way to do it; in addition, the -envelope processing here is just for demo purposes and isn't needed. -""" - -# For testing different buffer sizes -rate = 48000 - -fg = gr.flow_graph() - -# Two streams of floats -a = gr.sig_source_f(rate, gr.GR_SIN_WAVE, 350, 0.5, 0.0); -b = gr.sig_source_f(rate, gr.GR_SIN_WAVE, 440, 0.5, 0.0); - -# Turn them into vectors of length 'size' -av = gr.stream_to_vector(gr.sizeof_float, rate) -bv = gr.stream_to_vector(gr.sizeof_float, rate) - -# Make a vector adder for float vectors -adder = gr.add_vff(rate) - -# Make a 1 Hz sine envelope -envelope = [sin(2*pi*x/rate)*0.5 for x in range(rate)] -multiplier = gr.multiply_const_vff(envelope) - -# Make an offset adder -offset = gr.add_const_vff((0.5,)*rate) - -# Turn the vector back into a stream of floats -result = gr.vector_to_stream(gr.sizeof_float, rate) - -# Play it -sink = audio.sink(rate) - -fg.connect(a, av) -fg.connect(b, bv) -fg.connect(av, (adder, 0)) -fg.connect(bv, (adder, 1)) -fg.connect(adder, multiplier, offset, result, sink) - -try: - fg.run() -except KeyboardInterrupt: - pass diff --git a/gnuradio-examples/python/channel-coding/Makefile.am b/gnuradio-examples/python/channel-coding/Makefile.am deleted file mode 100644 index 3a6c33820e..0000000000 --- a/gnuradio-examples/python/channel-coding/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -# -# Copyright 2004 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -EXTRA_DIST = \ - README \ - fsm_utils.py \ - test_tcm.py \ - test_tcm1.py \ - test_tcm2.py \ - test_tcm_parallel.py \ - test_tcm_combined.py \ - test_sccc_hard.py \ - test_sccc_soft.py \ - test_sccc_turbo.py \ - test_viterbi_equalization1.py \ - test_viterbi_equalization.py \ - test_turbo_equalization.py \ - test_turbo_equalization1.py \ - test_turbo_equalization2.py - -SUBDIRS = fsm_files - -MOSTLYCLEANFILES = *.pyc diff --git a/gnuradio-examples/python/channel-coding/README b/gnuradio-examples/python/channel-coding/README deleted file mode 100644 index d5bad85f57..0000000000 --- a/gnuradio-examples/python/channel-coding/README +++ /dev/null @@ -1,53 +0,0 @@ -Here we have several test programs for use with the gr-trellis implementation. -Documentation can be found in -http://gnuradio.utah.edu/svn/gnuradio/trunk/gr-trellis/doc/gr-trellis.html - -fsm_utils.py contains several useful functions. - -fsm_files is a directory with some FSM definitions - -If you just want to see what these programs do, run each of the following: - -./test_tcm.py fsm_files/awgn1o2_4.fsm 6.0 1000 -./test_tcm1.py fsm_files/awgn1o2_4.fsm 6.0 1000 -./test_tcm2.py 6.0 1000 -./test_tcm_combined.py fsm_files/awgn1o2_4.fsm 6.0 1000 -./test_tcm_parallel.py fsm_files/awgn1o2_4.fsm 6.0 1000 - -./test_sccc_hard.py fsm_files/awgn1o2_4.fsm fsm_files/awgn2o3_4_msb.fsm 10.0 100 -./test_sccc_soft.py fsm_files/awgn1o2_4.fsm fsm_files/awgn2o3_4_msb.fsm 8.0 100 -./test_sccc_turbo.py fsm_files/awgn1o2_4.fsm fsm_files/awgn2o3_4_msb.fsm 5.0 100 - -./test_viterbi_equalization.py 12.0 100 -./test_viterbi_equalization1.py 12.0 100 -./test_turbo_equalization1.py fsm_files/awgn1o2_4.fsm 8.0 100 -./test_turbo_equalization2.py fsm_files/awgn1o2_4.fsm 8.0 100 - - -In your terminal you will see something like this: - - -$ ./test_tcm.py fsm_files/awgn1o2_4.fsm 6.0 1000 -100 98 9.80e-01 102400 9 8.79e-05 -200 198 9.90e-01 204800 20 9.77e-05 -300 298 9.93e-01 307200 40 1.30e-04 -400 398 9.95e-01 409600 1074 2.62e-03 -500 498 9.96e-01 512000 1081 2.11e-03 -600 598 9.97e-01 614400 1090 1.77e-03 -700 698 9.97e-01 716800 1097 1.53e-03 -800 798 9.98e-01 819200 1107 1.35e-03 -900 898 9.98e-01 921600 1120 1.22e-03 -1000 998 9.98e-01 1024000 1129 1.10e-03 -1000 998 9.98e-01 1024000 1129 1.10e-03 - -which gives you information about the: -number of transmitted packets -number of packets in error -estimated packet error rate -number of transmitted shorts (or symbols, or bits, depending on the specific program) -number of shorts (or symbols, or bits) in error -estimated short (or symbol, or bit) error rate - -for instance, the final number 1.10e-03 is the error rate estimate by sending 1000 -packets of 1024 shorts each, using an 1/2 4-state convolutional code -and QPSK modulation through an AWGN with Es/N0 = 6.0 dB diff --git a/gnuradio-examples/python/channel-coding/fsm_files/Makefile.am b/gnuradio-examples/python/channel-coding/fsm_files/Makefile.am deleted file mode 100644 index 081f62fc3f..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/Makefile.am +++ /dev/null @@ -1,37 +0,0 @@ -# -# Copyright 2004 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -EXTRA_DIST = \ - awgn1o2_128.fsm \ - awgn1o2_16.fsm \ - awgn1o2_4.fsm \ - awgn1o2_8.fsm \ - awgn2o3_16.fsm \ - awgn2o3_4.fsm \ - awgn2o3_4_msb.fsm \ - awgn2o3_4_msbG.fsm \ - awgn2o3_8.fsm \ - awgn2o4_4.fsm \ - disconnected.fsm \ - rep3.fsm \ - rep5.fsm \ - simple.fsm - diff --git a/gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_128.fsm b/gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_128.fsm deleted file mode 100644 index bb79c59da4..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_128.fsm +++ /dev/null @@ -1,265 +0,0 @@ -2 128 4 - -0 64 -0 64 -1 65 -1 65 -2 66 -2 66 -3 67 -3 67 -4 68 -4 68 -5 69 -5 69 -6 70 -6 70 -7 71 -7 71 -8 72 -8 72 -9 73 -9 73 -10 74 -10 74 -11 75 -11 75 -12 76 -12 76 -13 77 -13 77 -14 78 -14 78 -15 79 -15 79 -16 80 -16 80 -17 81 -17 81 -18 82 -18 82 -19 83 -19 83 -20 84 -20 84 -21 85 -21 85 -22 86 -22 86 -23 87 -23 87 -24 88 -24 88 -25 89 -25 89 -26 90 -26 90 -27 91 -27 91 -28 92 -28 92 -29 93 -29 93 -30 94 -30 94 -31 95 -31 95 -32 96 -32 96 -33 97 -33 97 -34 98 -34 98 -35 99 -35 99 -36 100 -36 100 -37 101 -37 101 -38 102 -38 102 -39 103 -39 103 -40 104 -40 104 -41 105 -41 105 -42 106 -42 106 -43 107 -43 107 -44 108 -44 108 -45 109 -45 109 -46 110 -46 110 -47 111 -47 111 -48 112 -48 112 -49 113 -49 113 -50 114 -50 114 -51 115 -51 115 -52 116 -52 116 -53 117 -53 117 -54 118 -54 118 -55 119 -55 119 -56 120 -56 120 -57 121 -57 121 -58 122 -58 122 -59 123 -59 123 -60 124 -60 124 -61 125 -61 125 -62 126 -62 126 -63 127 -63 127 - -0 3 -3 0 -1 2 -2 1 -3 0 -0 3 -2 1 -1 2 -1 2 -2 1 -0 3 -3 0 -2 1 -1 2 -3 0 -0 3 -1 2 -2 1 -0 3 -3 0 -2 1 -1 2 -3 0 -0 3 -0 3 -3 0 -1 2 -2 1 -3 0 -0 3 -2 1 -1 2 -2 1 -1 2 -3 0 -0 3 -1 2 -2 1 -0 3 -3 0 -3 0 -0 3 -2 1 -1 2 -0 3 -3 0 -1 2 -2 1 -3 0 -0 3 -2 1 -1 2 -0 3 -3 0 -1 2 -2 1 -2 1 -1 2 -3 0 -0 3 -1 2 -2 1 -0 3 -3 0 -2 1 -1 2 -3 0 -0 3 -1 2 -2 1 -0 3 -3 0 -3 0 -0 3 -2 1 -1 2 -0 3 -3 0 -1 2 -2 1 -3 0 -0 3 -2 1 -1 2 -0 3 -3 0 -1 2 -2 1 -2 1 -1 2 -3 0 -0 3 -1 2 -2 1 -0 3 -3 0 -0 3 -3 0 -1 2 -2 1 -3 0 -0 3 -2 1 -1 2 -1 2 -2 1 -0 3 -3 0 -2 1 -1 2 -3 0 -0 3 -1 2 -2 1 -0 3 -3 0 -2 1 -1 2 -3 0 -0 3 -0 3 -3 0 -1 2 -2 1 -3 0 -0 3 -2 1 -1 2 - - - -GM1o2_128=[1+D+D^2+D^5+D^7 1+D^3+D^4+D^5+D^6+D^7] - =[11100101 10011111] - =[229 159] diff --git a/gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_16.fsm b/gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_16.fsm deleted file mode 100644 index cdab41359e..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_16.fsm +++ /dev/null @@ -1,39 +0,0 @@ -2 16 4 - -0 8 -0 8 -1 9 -1 9 -2 10 -2 10 -3 11 -3 11 -4 12 -4 12 -5 13 -5 13 -6 14 -6 14 -7 15 -7 15 - -0 3 -3 0 -1 2 -2 1 -1 2 -2 1 -0 3 -3 0 -2 1 -1 2 -3 0 -0 3 -3 0 -0 3 -2 1 -1 2 - - - -GM1o2_16=[1+D+D^4 1+D^2+D^3+D^4 ] = [25,23] (decimal) diff --git a/gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_4.fsm b/gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_4.fsm deleted file mode 100644 index fb316b5ef8..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_4.fsm +++ /dev/null @@ -1,14 +0,0 @@ -2 4 4 - -0 2 -0 2 -1 3 -1 3 - -0 3 -3 0 -1 2 -2 1 - -AWGN CC from Proakis-Salehi pg 779 -GM1o2_4=[1+D^2, 1+D+D^2] = [5, 7] (in decimal); diff --git a/gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_8.fsm b/gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_8.fsm deleted file mode 100644 index 604bac6c2c..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/awgn1o2_8.fsm +++ /dev/null @@ -1,24 +0,0 @@ -2 8 4 - -0 4 -0 4 -1 5 -1 5 -2 6 -2 6 -3 7 -3 7 - - -0 3 -3 0 -1 2 -2 1 -3 0 -0 3 -2 1 -1 2 - - -1/2 8-state code (Proakis pg. 493) -GM1o2_8=[ 1+D+D^3 1+D+D^2+D^3] =[13 , 15] (decimal) diff --git a/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_16.fsm b/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_16.fsm deleted file mode 100644 index 9630cd9afb..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_16.fsm +++ /dev/null @@ -1,40 +0,0 @@ -4 16 8 - -0 8 4 12 -0 8 4 12 -0 8 4 12 -0 8 4 12 -1 9 5 13 -1 9 5 13 -1 9 5 13 -1 9 5 13 -2 10 6 14 -2 10 6 14 -2 10 6 14 -2 10 6 14 -3 11 7 15 -3 11 7 15 -3 11 7 15 -3 11 7 15 - -0 1 7 6 -6 7 1 0 -3 2 4 5 -5 4 2 3 -2 3 5 4 -4 5 3 2 -1 0 6 7 -7 6 0 1 -4 5 3 2 -2 3 5 4 -7 6 0 1 -1 0 6 7 -6 7 1 0 -0 1 7 6 -5 4 2 3 -3 2 4 5 - - -2/3 code generated from the awgn 1/2 code with 16 states and puncturing the 4th bit. -d_free= - diff --git a/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_4.fsm b/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_4.fsm deleted file mode 100644 index 3ac57be18d..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_4.fsm +++ /dev/null @@ -1,15 +0,0 @@ -4 4 8 - -0 1 2 3 -0 1 2 3 -0 1 2 3 -0 1 2 3 - -0 7 4 3 -3 4 7 0 -5 2 1 6 -6 1 2 5 - -I don't remeber how I generated this one... -it is a bit better than awgn2o3_4_msb and worse -than awgn2o3_4_msbG. diff --git a/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_4_msb.fsm b/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_4_msb.fsm deleted file mode 100644 index 551b711019..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_4_msb.fsm +++ /dev/null @@ -1,46 +0,0 @@ -4 4 8 - -0 1 2 3 -0 1 2 3 -0 1 2 3 -0 1 2 3 - -0 5 3 6 -4 1 7 2 -7 2 4 1 -3 6 0 5 - - -This is generated by the 1/2 AWGN code (5 7) operated twice, ie, -(xk+1 xki) [xk-1 xk-2] -> [xk+1 xki]. -We also puncture the first (MSB) bit. -This code is worse than awgn2o3_4_msbG and slightly worse than -awgn2o3_4, BUT seems to be a good innner code for sctcm (with 8PSK natural). - -intermediate states: - -00 21 02 23 -00 21 02 23 -10 31 12 33 -10 31 12 33 - -output before puncturing: - -00 31 03 32 -30 01 33 02 -13 22 10 21 -23 12 20 11 - -output after punturing the MSB: - -00 11 03 12 -10 01 13 02 -13 02 10 01 -03 12 00 11 - -and in decimal: - -0 5 3 6 -4 1 7 2 -7 2 4 1 -3 6 0 5 diff --git a/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_4_msbG.fsm b/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_4_msbG.fsm deleted file mode 100644 index 8956c53da2..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_4_msbG.fsm +++ /dev/null @@ -1,60 +0,0 @@ -4 4 8 - -0 1 2 3 -0 1 2 3 -0 1 2 3 -0 1 2 3 - -0 4 2 6 -5 1 3 7 -3 7 5 1 - - -This is generated by the 1/2 AWGN code (5 7) operated twice, ie, -(xk+1 xki) [xk-1 xk-2] -> [xk+1 xki]. -We also puncture the first (MSB) bit and Gray map the symbols. - -intermediate states: - -00 21 02 23 -00 21 02 23 -10 31 12 33 -10 31 12 33 - -output before puncturing: - -00 31 03 32 -30 01 33 02 -13 22 10 21 -23 12 20 11 - -output after punturing the MSB: - -00 11 03 12 -10 01 13 02 -13 02 10 01 -03 12 00 11 - -and in decimal: - -0 5 3 6 -4 1 7 2 -7 2 4 1 -3 6 0 5 - -After Gray mapping: -label -> phase -0 -> 0 -1 -> 0 -2 -> 7 -3 -> 2 -4 -> 5 -5 -> 4 -6 -> 6 -7 -> 3 - -0 4 2 6 -5 1 3 7 -3 7 5 1 -2 6 0 4 - diff --git a/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_8.fsm b/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_8.fsm deleted file mode 100644 index 34deeb68cb..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/awgn2o3_8.fsm +++ /dev/null @@ -1,25 +0,0 @@ -4 8 8 - -0 4 2 6 -0 4 2 6 -0 4 2 6 -0 4 2 6 -1 5 3 7 -1 5 3 7 -1 5 3 7 -1 5 3 7 - - -0 1 7 6 -6 7 1 0 -3 2 4 5 -5 4 2 3 -6 7 1 0 -0 1 7 6 -5 4 2 3 -3 2 4 5 - - - -This is generated by the 1/2 8-state AWGN code (15 17) by puncturing the fourth bit. ---> d_free=??? diff --git a/gnuradio-examples/python/channel-coding/fsm_files/awgn2o4_4.fsm b/gnuradio-examples/python/channel-coding/fsm_files/awgn2o4_4.fsm deleted file mode 100644 index a895be8965..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/awgn2o4_4.fsm +++ /dev/null @@ -1,36 +0,0 @@ -4 4 16 - -0 1 2 3 -0 1 2 3 -0 1 2 3 -0 1 2 3 - - 0 13 3 14 -12 1 15 2 - 7 10 4 9 -11 6 8 5 - - -This is generated by the 1/2 AWGN code (5 7) operated twice, ie, -(xk+1 xki) [xk-1 xk-2] -> [xk+1 xki]. - -intermediate states: - -00 21 02 23 -00 21 02 23 -10 31 12 33 -10 31 12 33 - -output: - -00 31 03 32 -30 01 33 02 -13 22 10 21 -23 12 20 11 - -and in decimal: - - 0 13 3 14 -12 1 15 2 - 7 10 4 9 -11 6 8 5 diff --git a/gnuradio-examples/python/channel-coding/fsm_files/disconnected.fsm b/gnuradio-examples/python/channel-coding/fsm_files/disconnected.fsm deleted file mode 100644 index 847963e7b2..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/disconnected.fsm +++ /dev/null @@ -1,11 +0,0 @@ -1 4 1 - -1 -0 -3 -2 - -0 -0 -0 -0 diff --git a/gnuradio-examples/python/channel-coding/fsm_files/irregular.fsm b/gnuradio-examples/python/channel-coding/fsm_files/irregular.fsm deleted file mode 100644 index 80b82b889d..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/irregular.fsm +++ /dev/null @@ -1,11 +0,0 @@ -2 2 2 - -0 0 -0 1 - -0 1 -0 1 - - -useless irregular FSM for testing. state 0 has 3 incoming edges and state -1 has 1 incoming edge. diff --git a/gnuradio-examples/python/channel-coding/fsm_files/rep3.fsm b/gnuradio-examples/python/channel-coding/fsm_files/rep3.fsm deleted file mode 100644 index ef1bd1f025..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/rep3.fsm +++ /dev/null @@ -1,8 +0,0 @@ -2 1 8 - -0 0 - -0 7 - -1/3 repetition code (with binary input). -There is only one state, since this is essentially a memoryless system. diff --git a/gnuradio-examples/python/channel-coding/fsm_files/rep5.fsm b/gnuradio-examples/python/channel-coding/fsm_files/rep5.fsm deleted file mode 100644 index 581858ec10..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/rep5.fsm +++ /dev/null @@ -1,7 +0,0 @@ -2 1 8 - -0 0 - -0 7 - -1/3 repetiotion code diff --git a/gnuradio-examples/python/channel-coding/fsm_files/simple.fsm b/gnuradio-examples/python/channel-coding/fsm_files/simple.fsm deleted file mode 100644 index 07fb0852f6..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_files/simple.fsm +++ /dev/null @@ -1,13 +0,0 @@ -1 4 1 - -1 -2 -3 -0 - -0 -0 -0 -0 - -essentially this fsm has no inputs and no outputs; it ijust cycles through all 4 states. diff --git a/gnuradio-examples/python/channel-coding/fsm_utils.py b/gnuradio-examples/python/channel-coding/fsm_utils.py deleted file mode 100755 index 1b011246c8..0000000000 --- a/gnuradio-examples/python/channel-coding/fsm_utils.py +++ /dev/null @@ -1,213 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - - -import re -import math -import sys -import operator - -from gnuradio import trellis - - - -###################################################################### -# Decimal to any base conversion. -# Convert 'num' to a list of 'l' numbers representing 'num' -# to base 'base' (most significant symbol first). -###################################################################### -def dec2base(num,base,l): - s=range(l) - n=num - for i in range(l): - s[l-i-1]=n%base - n=int(n/base) - if n!=0: - print 'Number ', num, ' requires more than ', l, 'digits.' - return s - - -###################################################################### -# Conversion from any base to decimal. -# Convert a list 's' of symbols to a decimal number -# (most significant symbol first) -###################################################################### -def base2dec(s,base): - num=0 - for i in range(len(s)): - num=num*base+s[i] - return num - - -###################################################################### -# Generate a new FSM representing the concatenation of two FSMs -###################################################################### -def fsm_concatenate(f1,f2): - if f1.O() > f2.I(): - print "Not compatible FSMs\n" - I=f1.I() - S=f1.S()*f2.S() - O=f2.O() - nsm=list([0]*I*S) - osm=list([0]*I*S) - for s1 in range(f1.S()): - for s2 in range(f2.S()): - for i in range(f1.I()): - ns1=f1.NS()[s1*f1.I()+i] - o1=f1.OS()[s1*f1.I()+i] - ns2=f2.NS()[s2*f2.I()+o1] - o2=f2.OS()[s2*f2.I()+o1] - - s=s1*f2.S()+s2 - ns=ns1*f2.S()+ns2 - nsm[s*I+i]=ns - osm[s*I+i]=o2 - - - f=trellis.fsm(I,S,O,nsm,osm) - return f - -###################################################################### -# Generate a new FSM representing n stages through the original FSM -###################################################################### -def fsm_radix(f,n): - I=f.I()**n - S=f.S() - O=f.O()**n - nsm=list([0]*I*S) - osm=list([0]*I*S) - for s in range(f.S()): - for i in range(I): - ii=dec2base(i,f.I(),n) - oo=list([0]*n) - ns=s - for k in range(n): - oo[k]=f.OS()[ns*f.I()+ii[k]] - ns=f.NS()[ns*f.I()+ii[k]] - - nsm[s*I+i]=ns - osm[s*I+i]=base2dec(oo,f.O()) - - - f=trellis.fsm(I,S,O,nsm,osm) - return f - - - - -###################################################################### -# Automatically generate the lookup table that maps the FSM outputs -# to channel inputs corresponding to a channel 'channel' and a modulation -# 'mod'. Optional normalization of channel to unit energy. -# This table is used by the 'metrics' block to translate -# channel outputs to metrics for use with the Viterbi algorithm. -# Limitations: currently supports only one-dimensional modulations. -###################################################################### -def make_isi_lookup(mod,channel,normalize): - dim=mod[0] - constellation = mod[1] - - if normalize: - p = 0 - for i in range(len(channel)): - p = p + channel[i]**2 - for i in range(len(channel)): - channel[i] = channel[i]/math.sqrt(p) - - lookup=range(len(constellation)**len(channel)) - for o in range(len(constellation)**len(channel)): - ss=dec2base(o,len(constellation),len(channel)) - ll=0 - for i in range(len(channel)): - ll=ll+constellation[ss[i]]*channel[i] - lookup[o]=ll - return (1,lookup) - - - - - - -###################################################################### -# A list of common modulations. -# Format: (dimensionality,constellation) -###################################################################### -pam2 = (1,[-1, 1]) -pam4 = (1,[-3, -1, 3, 1]) # includes Gray mapping -pam8 = (1,[-7, -5, -3, -1, 1, 3, 5, 7]) - -psk4=(2,[1, 0, \ - 0, 1, \ - 0, -1,\ - -1, 0]) # includes Gray mapping -psk8=(2,[math.cos(2*math.pi*0/8), math.sin(2*math.pi*0/8), \ - math.cos(2*math.pi*1/8), math.sin(2*math.pi*1/8), \ - math.cos(2*math.pi*2/8), math.sin(2*math.pi*2/8), \ - math.cos(2*math.pi*3/8), math.sin(2*math.pi*3/8), \ - math.cos(2*math.pi*4/8), math.sin(2*math.pi*4/8), \ - math.cos(2*math.pi*5/8), math.sin(2*math.pi*5/8), \ - math.cos(2*math.pi*6/8), math.sin(2*math.pi*6/8), \ - math.cos(2*math.pi*7/8), math.sin(2*math.pi*7/8)]) - -orth2 = (2,[1, 0, \ - 0, 1]) -orth4=(4,[1, 0, 0, 0, \ - 0, 1, 0, 0, \ - 0, 0, 1, 0, \ - 0, 0, 0, 1]) - -###################################################################### -# A list of channels to be tested -###################################################################### - -# C test channel (J. Proakis, Digital Communications, McGraw-Hill Inc., 2001) -c_channel = [0.227, 0.460, 0.688, 0.460, 0.227] - - - - - - - - - - -if __name__ == '__main__': - f1=trellis.fsm('fsm_files/awgn1o2_4.fsm') - #f2=trellis.fsm('fsm_files/awgn2o3_4.fsm') - print f1.I(), f1.S(), f1.O() - print f1.NS() - print f1.OS() - #print f2.I(), f2.S(), f2.O() - #print f2.NS() - #print f2.OS() - ##f1.write_trellis_svg('f1.svg',4) - #f2.write_trellis_svg('f2.svg',4) - #f=fsm_concatenate(f1,f2) - f=fsm_radix(f1,2) - - print "----------\n" - print f.I(), f.S(), f.O() - print f.NS() - print f.OS() - #f.write_trellis_svg('f.svg',4) - diff --git a/gnuradio-examples/python/channel-coding/test_sccc_hard.py b/gnuradio-examples/python/channel-coding/test_sccc_hard.py deleted file mode 100755 index d634282fe7..0000000000 --- a/gnuradio-examples/python/channel-coding/test_sccc_hard.py +++ /dev/null @@ -1,101 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import audio -from gnuradio import trellis -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed): - fg = gr.flow_graph () - - - # TX - src = gr.lfsr_32k_source_s() - src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality - enc_out = trellis.encoder_ss(fo,0) # initial state = 0 - inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short) - enc_in = trellis.encoder_ss(fi,0) # initial state = 0 - mod = gr.chunks_to_symbols_sf(constellation,dimensionality) - - # CHANNEL - add = gr.add_ff() - noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) - - # RX - metrics_in = trellis.metrics_f(fi.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner Viterbi - va_in = trellis.viterbi_s(fi,K,0,-1) # Put -1 if the Initial/Final states are not set. - deinter = trellis.permutation(interleaver.K(),interleaver.DEINTER(),1,gr.sizeof_short) - metrics_out = trellis.metrics_s(fo.O(),1,[0,1,2,3],trellis.TRELLIS_HARD_SYMBOL) # data preprocessing to generate metrics for outer Viterbi (hard decisions) - va_out = trellis.viterbi_s(fo,K,0,-1) # Put -1 if the Initial/Final states are not set. - fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = gr.check_lfsr_32k_s() - - fg.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod) - fg.connect (mod,(add,0)) - fg.connect (noise,(add,1)) - fg.connect (add,metrics_in) - fg.connect (metrics_in,va_in,deinter,metrics_out,va_out,fsmi2s,dst) - - fg.run() - - ntotal = dst.ntotal () - nright = dst.nright () - runlength = dst.runlength () - return (ntotal,ntotal-nright) - - -def main(args): - nargs = len (args) - if nargs == 4: - fname_out=args[0] - fname_in=args[1] - esn0_db=float(args[2]) # Es/No in dB - rep=int(args[3]) # number of times the experiment is run to collect enough errors - else: - sys.stderr.write ('usage: test_tcm.py fsm_name_out fsm_fname_in Es/No_db repetitions\n') - sys.exit (1) - - # system parameters - Kb=1024*16 # packet size in bits (make it multiple of 16 so it can be packed in a short) - fo=trellis.fsm(fname_out) # get the outer FSM specification from a file - fi=trellis.fsm(fname_in) # get the innner FSM specification from a file - bitspersymbol = int(round(math.log(fo.I())/math.log(2))) # bits per FSM input symbol - if fo.O() != fi.I(): - sys.stderr.write ('Incompatible cardinality between outer and inner FSM.\n') - sys.exit (1) - K=Kb/bitspersymbol # packet size in trellis steps - interleaver=trellis.interleaver(K,666) # construct a random interleaver - modulation = fsm_utils.psk8 # see fsm_utlis.py for available predefined modulations - dimensionality = modulation[0] - constellation = modulation[1] - if len(constellation)/dimensionality != fi.O(): - sys.stderr.write ('Incompatible FSM output cardinality and modulation size.\n') - sys.exit (1) - # calculate average symbol energy - Es = 0 - for i in range(len(constellation)): - Es = Es + constellation[i]**2 - Es = Es / (len(constellation)/dimensionality) - N0=Es/pow(10.0,esn0_db/10.0); # calculate noise variance - - tot_s=0 # total number of transmitted shorts - terr_s=0 # total number of shorts in error - terr_p=0 # total number of packets in error - for i in range(rep): - (s,e)=run_test(fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,N0,-long(666+i)) # run experiment with different seed to get different noise realizations - tot_s=tot_s+s - terr_s=terr_s+e - terr_p=terr_p+(terr_s!=0) - if ((i+1)%100==0) : # display progress - print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - # estimate of the (short or bit) error rate - print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - - -if __name__ == '__main__': - main (sys.argv[1:]) diff --git a/gnuradio-examples/python/channel-coding/test_sccc_soft.py b/gnuradio-examples/python/channel-coding/test_sccc_soft.py deleted file mode 100755 index 23e6553ca1..0000000000 --- a/gnuradio-examples/python/channel-coding/test_sccc_soft.py +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import audio -from gnuradio import trellis -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - - - - -def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed): - fg = gr.flow_graph () - - - # TX - src = gr.lfsr_32k_source_s() - src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality - enc_out = trellis.encoder_ss(fo,0) # initial state = 0 - inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short) - enc_in = trellis.encoder_ss(fi,0) # initial state = 0 - mod = gr.chunks_to_symbols_sf(constellation,dimensionality) - - # CHANNEL - add = gr.add_ff() - noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) - - # RX - metrics_in = trellis.metrics_f(fi.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner Viterbi - gnd = gr.vector_source_f([0],True); - siso_in = trellis.siso_f(fi,K,0,-1,True,False,trellis.TRELLIS_MIN_SUM) # Put -1 if the Initial/Final states are not set. - deinter = trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float) - va_out = trellis.viterbi_s(fo,K,0,-1) # Put -1 if the Initial/Final states are not set. - fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = gr.check_lfsr_32k_s() - - fg.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod) - fg.connect (mod,(add,0)) - fg.connect (noise,(add,1)) - fg.connect (add,metrics_in) - fg.connect (gnd,(siso_in,0)) - fg.connect (metrics_in,(siso_in,1)) - fg.connect (siso_in,deinter,va_out,fsmi2s,dst) - - fg.run() - - ntotal = dst.ntotal () - nright = dst.nright () - runlength = dst.runlength () - return (ntotal,ntotal-nright) - - -def main(args): - nargs = len (args) - if nargs == 4: - fname_out=args[0] - fname_in=args[1] - esn0_db=float(args[2]) # Es/No in dB - rep=int(args[3]) # number of times the experiment is run to collect enough errors - else: - sys.stderr.write ('usage: test_tcm.py fsm_name_out fsm_fname_in Es/No_db repetitions\n') - sys.exit (1) - - # system parameters - Kb=1024*16 # packet size in bits (make it multiple of 16 so it can be packed in a short) - fo=trellis.fsm(fname_out) # get the outer FSM specification from a file - fi=trellis.fsm(fname_in) # get the innner FSM specification from a file - bitspersymbol = int(round(math.log(fo.I())/math.log(2))) # bits per FSM input symbol - if fo.O() != fi.I(): - sys.stderr.write ('Incompatible cardinality between outer and inner FSM.\n') - sys.exit (1) - K=Kb/bitspersymbol # packet size in trellis steps - interleaver=trellis.interleaver(K,666) # construct a random interleaver - modulation = fsm_utils.psk8 # see fsm_utlis.py for available predefined modulations - dimensionality = modulation[0] - constellation = modulation[1] - if len(constellation)/dimensionality != fi.O(): - sys.stderr.write ('Incompatible FSM output cardinality and modulation size.\n') - sys.exit (1) - # calculate average symbol energy - Es = 0 - for i in range(len(constellation)): - Es = Es + constellation[i]**2 - Es = Es / (len(constellation)/dimensionality) - N0=Es/pow(10.0,esn0_db/10.0); # calculate noise variance - - - tot_s=0 # total number of transmitted shorts - terr_s=0 # total number of shorts in error - terr_p=0 # total number of packets in error - for i in range(rep): - (s,e)=run_test(fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,N0,-long(666+i)) # run experiment with different seed to get different noise realizations - tot_s=tot_s+s - terr_s=terr_s+e - terr_p=terr_p+(terr_s!=0) - if ((i+1)%100==0) : # display progress - print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - # estimate of the (short or bit) error rate - print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - - - -if __name__ == '__main__': - main (sys.argv[1:]) diff --git a/gnuradio-examples/python/channel-coding/test_sccc_turbo.py b/gnuradio-examples/python/channel-coding/test_sccc_turbo.py deleted file mode 100755 index f67fb09223..0000000000 --- a/gnuradio-examples/python/channel-coding/test_sccc_turbo.py +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import audio -from gnuradio import trellis -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - - - -def make_rx(fg,fo,fi,dimensionality,constellation,K,interleaver,IT,Es,N0,type): - metrics_in = trellis.metrics_f(fi.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner Viterbi - scale = gr.multiply_const_ff(1.0/N0) - gnd = gr.vector_source_f([0],True); - - inter=[] - deinter=[] - siso_in=[] - siso_out=[] - - # generate all blocks - for it in range(IT): - inter.append( trellis.permutation(interleaver.K(),interleaver.INTER(),fi.I(),gr.sizeof_float) ) - siso_in.append( trellis.siso_f(fi,K,0,-1,True,False,type) ) - deinter.append( trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float) ) - if it < IT-1: - siso_out.append( trellis.siso_f(fo,K,0,-1,False,True,type) ) - else: - siso_out.append( trellis.viterbi_s(fo,K,0,-1) ) # no soft outputs needed - - # connect first stage - fg.connect (gnd,inter[0]) - fg.connect (metrics_in,scale) - fg.connect (scale,(siso_in[0],1)) - - # connect the rest - for it in range(IT): - if it < IT-1: - fg.connect (metrics_in,(siso_in[it+1],1)) - fg.connect (siso_in[it],deinter[it],(siso_out[it],1)) - fg.connect (gnd,(siso_out[it],0)) - fg.connect (siso_out[it],inter[it+1]) - fg.connect (inter[it],(siso_in[it],0)) - else: - fg.connect (siso_in[it],deinter[it],siso_out[it]) - fg.connect (inter[it],(siso_in[it],0)) - - return (metrics_in,siso_out[IT-1]) - - -def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed): - fg = gr.flow_graph () - - - # TX - src = gr.lfsr_32k_source_s() - src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality - enc_out = trellis.encoder_ss(fo,0) # initial state = 0 - inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short) - enc_in = trellis.encoder_ss(fi,0) # initial state = 0 - mod = gr.chunks_to_symbols_sf(constellation,dimensionality) - - # CHANNEL - add = gr.add_ff() - noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) - - # RX - (head,tail) = make_rx(fg,fo,fi,dimensionality,constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM) - #(head,tail) = make_rx(fg,fo,fi,dimensionality,constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_SUM_PRODUCT) - fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = gr.check_lfsr_32k_s() - - fg.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod) - fg.connect (mod,(add,0)) - fg.connect (noise,(add,1)) - fg.connect (add,head) - fg.connect (tail,fsmi2s,dst) - - fg.run() - - #print enc_out.ST(), enc_in.ST() - - ntotal = dst.ntotal () - nright = dst.nright () - runlength = dst.runlength () - return (ntotal,ntotal-nright) - - -def main(args): - nargs = len (args) - if nargs == 4: - fname_out=args[0] - fname_in=args[1] - esn0_db=float(args[2]) # Es/No in dB - rep=int(args[3]) # number of times the experiment is run to collect enough errors - else: - sys.stderr.write ('usage: test_tcm.py fsm_name_out fsm_fname_in Es/No_db repetitions\n') - sys.exit (1) - - # system parameters - Kb=1024*16 # packet size in bits (make it multiple of 16 so it can be packed in a short) - fo=trellis.fsm(fname_out) # get the outer FSM specification from a file - fi=trellis.fsm(fname_in) # get the innner FSM specification from a file - bitspersymbol = int(round(math.log(fo.I())/math.log(2))) # bits per FSM input symbol - if fo.O() != fi.I(): - sys.stderr.write ('Incompatible cardinality between outer and inner FSM.\n') - sys.exit (1) - K=Kb/bitspersymbol # packet size in trellis steps - interleaver=trellis.interleaver(K,666) # construct a random interleaver - modulation = fsm_utils.psk8 # see fsm_utlis.py for available predefined modulations - dimensionality = modulation[0] - constellation = modulation[1] - if len(constellation)/dimensionality != fi.O(): - sys.stderr.write ('Incompatible FSM output cardinality and modulation size.\n') - sys.exit (1) - # calculate average symbol energy - Es = 0 - for i in range(len(constellation)): - Es = Es + constellation[i]**2 - Es = Es / (len(constellation)/dimensionality) - N0=Es/pow(10.0,esn0_db/10.0); # calculate noise variance - IT = 3 # number of turbo iterations - - tot_s=0 # total number of transmitted shorts - terr_s=0 # total number of shorts in error - terr_p=0 # total number of packets in error - for i in range(rep): - (s,e)=run_test(fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,-long(666+i)) # run experiment with different seed to get different noise realizations - tot_s=tot_s+s - terr_s=terr_s+e - terr_p=terr_p+(terr_s!=0) - if ((i+1)%10==0): # display progress - print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - # estimate of the (short or bit) error rate - print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - - -if __name__ == '__main__': - main (sys.argv[1:]) diff --git a/gnuradio-examples/python/channel-coding/test_tcm.py b/gnuradio-examples/python/channel-coding/test_tcm.py deleted file mode 100755 index f225015580..0000000000 --- a/gnuradio-examples/python/channel-coding/test_tcm.py +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import audio -from gnuradio import trellis -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed): - fg = gr.flow_graph () - - - # TX - #packet = [0]*Kb - #for i in range(Kb-1*16): # last 16 bits = 0 to drive the final state to 0 - #packet[i] = random.randint(0, 1) # random 0s and 1s - #src = gr.vector_source_s(packet,False) - src = gr.lfsr_32k_source_s() - src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts - #b2s = gr.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts - s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality - enc = trellis.encoder_ss(f,0) # initial state = 0 - mod = gr.chunks_to_symbols_sf(constellation,dimensionality) - - # CHANNEL - add = gr.add_ff() - noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) - - # RX - metrics = trellis.metrics_f(f.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi - va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set. - fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - #s2b = gr.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits - #dst = gr.vector_sink_s(); - dst = gr.check_lfsr_32k_s() - - - fg.connect (src,src_head,s2fsmi,enc,mod) - #fg.connect (src,b2s,s2fsmi,enc,mod) - fg.connect (mod,(add,0)) - fg.connect (noise,(add,1)) - fg.connect (add,metrics) - fg.connect (metrics,va,fsmi2s,dst) - #fg.connect (metrics,va,fsmi2s,s2b,dst) - - - fg.run() - - # A bit of cheating: run the program once and print the - # final encoder state.. - # Then put it as the last argument in the viterbi block - #print "final state = " , enc.ST() - - ntotal = dst.ntotal () - nright = dst.nright () - runlength = dst.runlength () - #ntotal = len(packet) - #if len(dst.data()) != ntotal: - #print "Error: not enough data\n" - #nright = 0; - #for i in range(ntotal): - #if packet[i]==dst.data()[i]: - #nright=nright+1 - #else: - #print "Error in ", i - return (ntotal,ntotal-nright) - - - - -def main(args): - nargs = len (args) - if nargs == 3: - fname=args[0] - esn0_db=float(args[1]) # Es/No in dB - rep=int(args[2]) # number of times the experiment is run to collect enough errors - else: - sys.stderr.write ('usage: test_tcm.py fsm_fname Es/No_db repetitions\n') - sys.exit (1) - - # system parameters - f=trellis.fsm(fname) # get the FSM specification from a file - Kb=1024*16 # packet size in bits (make it multiple of 16 so it can be packed in a short) - bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol - K=Kb/bitspersymbol # packet size in trellis steps - modulation = fsm_utils.psk4 # see fsm_utlis.py for available predefined modulations - dimensionality = modulation[0] - constellation = modulation[1] - if len(constellation)/dimensionality != f.O(): - sys.stderr.write ('Incompatible FSM output cardinality and modulation size.\n') - sys.exit (1) - # calculate average symbol energy - Es = 0 - for i in range(len(constellation)): - Es = Es + constellation[i]**2 - Es = Es / (len(constellation)/dimensionality) - N0=Es/pow(10.0,esn0_db/10.0); # calculate noise variance - - tot_s=0 # total number of transmitted shorts - terr_s=0 # total number of shorts in error - terr_p=0 # total number of packets in error - for i in range(rep): - (s,e)=run_test(f,Kb,bitspersymbol,K,dimensionality,constellation,N0,-long(666+i)) # run experiment with different seed to get different noise realizations - tot_s=tot_s+s - terr_s=terr_s+e - terr_p=terr_p+(terr_s!=0) - if ((i+1)%100==0) : # display progress - print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - # estimate of the (short or bit) error rate - print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - - - -if __name__ == '__main__': - main (sys.argv[1:]) diff --git a/gnuradio-examples/python/channel-coding/test_tcm1.py b/gnuradio-examples/python/channel-coding/test_tcm1.py deleted file mode 100755 index 66d7131e38..0000000000 --- a/gnuradio-examples/python/channel-coding/test_tcm1.py +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import audio -from gnuradio import trellis -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed): - fg = gr.flow_graph () - - # TX - packet = [0]*Kb - # this for loop is TOO slow!!! - for i in range(Kb-1*16): # last 16 bits = 0 to drive the final state to 0 - packet[i] = random.randint(0, 1) # random 0s and 1s - src = gr.vector_source_s(packet,False) - #src = gr.lfsr_32k_source_s() - #src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts - b2s = gr.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts - s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality - enc = trellis.encoder_ss(f,0) # initial state = 0 - mod = gr.chunks_to_symbols_sf(constellation,dimensionality) - - - # CHANNEL - add = gr.add_ff() - noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) - - - # RX - metrics = trellis.metrics_f(f.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi - va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set. - fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - s2b = gr.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits - dst = gr.vector_sink_s(); - #dst = gr.check_lfsr_32k_s(); - - - #fg.connect (src,src_head,s2fsmi,enc,mod) - fg.connect (src,b2s,s2fsmi,enc,mod) - fg.connect (mod,(add,0)) - fg.connect (noise,(add,1)) - fg.connect (add,metrics) - #fg.connect (metrics,va,fsmi2s,dst) - fg.connect (metrics,va,fsmi2s,s2b,dst) - - - fg.run() - - # A bit of cheating: run the program once and print the - # final encoder state.. - # Then put it as the last argument in the viterbi block - #print "final state = " , enc.ST() - - #ntotal = dst.ntotal () - #nright = dst.nright () - #runlength = dst.runlength () - ntotal = len(packet) - if len(dst.data()) != ntotal: - print "Error: not enough data\n" - nright = 0; - # this for loop is TOO slow!!! - for i in range(ntotal): - if packet[i]==dst.data()[i]: - nright=nright+1 - #else: - #print "Error in ", i - return (ntotal,ntotal-nright) - - - - -def main(args): - nargs = len (args) - if nargs == 3: - fname=args[0] - esn0_db=float(args[1]) # Es/No in dB - rep=int(args[2]) # number of times the experiment is run to collect enough errors - else: - sys.stderr.write ('usage: test_tcm.py fsm_fname Es/No_db repetitions\n') - sys.exit (1) - - # system parameters - f=trellis.fsm(fname) # get the FSM specification from a file - Kb=1024*16 # packet size in bits (make it multiple of 16 so it can be packed in a short) - bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol - K=Kb/bitspersymbol # packet size in trellis steps - modulation = fsm_utils.psk4 # see fsm_utlis.py for available predefined modulations - dimensionality = modulation[0] - constellation = modulation[1] - if len(constellation)/dimensionality != f.O(): - sys.stderr.write ('Incompatible FSM output cardinality and modulation size.\n') - sys.exit (1) - # calculate average symbol energy - Es = 0 - for i in range(len(constellation)): - Es = Es + constellation[i]**2 - Es = Es / (len(constellation)/dimensionality) - N0=Es/pow(10.0,esn0_db/10.0); # noise variance - - tot_s=0 # total number of transmitted shorts - terr_s=0 # total number of shorts in error - terr_p=0 # total number of packets in error - for i in range(rep): - (s,e)=run_test(f,Kb,bitspersymbol,K,dimensionality,constellation,N0,-long(666+i)) # run experiment with different seed to get different noise realizations - tot_s=tot_s+s - terr_s=terr_s+e - terr_p=terr_p+(terr_s!=0) - if ((i+1)%1==0) : # display progress - print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - # estimate of the (short or bit) error rate - print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - - - -if __name__ == '__main__': - main (sys.argv[1:]) diff --git a/gnuradio-examples/python/channel-coding/test_tcm2.py b/gnuradio-examples/python/channel-coding/test_tcm2.py deleted file mode 100755 index 9680909ea6..0000000000 --- a/gnuradio-examples/python/channel-coding/test_tcm2.py +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import audio -from gnuradio import trellis -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed): - fg = gr.flow_graph () - - - # TX - #packet = [0]*Kb - #for i in range(Kb-1*16): # last 16 bits = 0 to drive the final state to 0 - #packet[i] = random.randint(0, 1) # random 0s and 1s - #src = gr.vector_source_s(packet,False) - src = gr.lfsr_32k_source_s() - src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts - #b2s = gr.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts - s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality - enc = trellis.encoder_ss(f,0) # initial state = 0 - mod = gr.chunks_to_symbols_sf(constellation,dimensionality) - - # CHANNEL - add = gr.add_ff() - noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) - - # RX - metrics = trellis.metrics_f(f.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi - va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set. - fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - #s2b = gr.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits - #dst = gr.vector_sink_s(); - dst = gr.check_lfsr_32k_s() - - - fg.connect (src,src_head,s2fsmi,enc,mod) - #fg.connect (src,b2s,s2fsmi,enc,mod) - fg.connect (mod,(add,0)) - fg.connect (noise,(add,1)) - fg.connect (add,metrics) - fg.connect (metrics,va,fsmi2s,dst) - #fg.connect (metrics,va,fsmi2s,s2b,dst) - - - fg.run() - - # A bit of cheating: run the program once and print the - # final encoder state.. - # Then put it as the last argument in the viterbi block - #print "final state = " , enc.ST() - - ntotal = dst.ntotal () - nright = dst.nright () - runlength = dst.runlength () - #ntotal = len(packet) - #if len(dst.data()) != ntotal: - #print "Error: not enough data\n" - #nright = 0; - #for i in range(ntotal): - #if packet[i]==dst.data()[i]: - #nright=nright+1 - #else: - #print "Error in ", i - return (ntotal,ntotal-nright) - - - - -def main(args): - nargs = len (args) - if nargs == 2: - esn0_db=float(args[0]) # Es/No in dB - rep=int(args[1]) # number of times the experiment is run to collect enough errors - else: - sys.stderr.write ('usage: test_tcm2.py Es/No_db repetitions\n') - sys.exit (1) - - # system parameters - f=trellis.fsm(1,2,[5,7]) # generate FSM specification from the generator matrix - Kb=1024*16 # packet size in bits (make it multiple of 16 so it can be packed in a short) - bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol - K=Kb/bitspersymbol # packet size in trellis steps - modulation = fsm_utils.psk4 # see fsm_utlis.py for available predefined modulations - dimensionality = modulation[0] - constellation = modulation[1] - if len(constellation)/dimensionality != f.O(): - sys.stderr.write ('Incompatible FSM output cardinality and modulation size.\n') - sys.exit (1) - # calculate average symbol energy - Es = 0 - for i in range(len(constellation)): - Es = Es + constellation[i]**2 - Es = Es / (len(constellation)/dimensionality) - N0=Es/pow(10.0,esn0_db/10.0); # calculate noise variance - - tot_s=0 # total number of transmitted shorts - terr_s=0 # total number of shorts in error - terr_p=0 # total number of packets in error - for i in range(rep): - (s,e)=run_test(f,Kb,bitspersymbol,K,dimensionality,constellation,N0,-long(666+i)) # run experiment with different seed to get different noise realizations - tot_s=tot_s+s - terr_s=terr_s+e - terr_p=terr_p+(terr_s!=0) - if ((i+1)%100==0) : # display progress - print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - # estimate of the (short or bit) error rate - print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - - -if __name__ == '__main__': - main (sys.argv[1:]) diff --git a/gnuradio-examples/python/channel-coding/test_tcm_combined.py b/gnuradio-examples/python/channel-coding/test_tcm_combined.py deleted file mode 100755 index 92e020bea3..0000000000 --- a/gnuradio-examples/python/channel-coding/test_tcm_combined.py +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import audio -from gnuradio import trellis -from gnuradio import eng_notation -import math -import sys -import fsm_utils - -def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed): - fg = gr.flow_graph () - - # TX - src = gr.lfsr_32k_source_s() - src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality - enc = trellis.encoder_ss(f,0) # initial state = 0 - mod = gr.chunks_to_symbols_sf(constellation,dimensionality) - - - # CHANNEL - add = gr.add_ff() - noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) - - - # RX - va = trellis.viterbi_combined_fs(f,K,0,-1,dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set. - fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = gr.check_lfsr_32k_s(); - - - fg.connect (src,src_head,s2fsmi,enc,mod) - fg.connect (mod,(add,0)) - fg.connect (noise,(add,1)) - fg.connect (add,va,fsmi2s,dst) - - - fg.run() - - # A bit of cheating: run the program once and print the - # final encoder state.. - # Then put it as the last argument in the viterbi block - #print "final state = " , enc.ST() - - ntotal = dst.ntotal () - nright = dst.nright () - runlength = dst.runlength () - - return (ntotal,ntotal-nright) - - - - -def main(args): - nargs = len (args) - if nargs == 3: - fname=args[0] - esn0_db=float(args[1]) # Es/No in dB - rep=int(args[2]) # number of times the experiment is run to collect enough errors - else: - sys.stderr.write ('usage: test_tcm_combined.py fsm_fname Es/No_db repetitions\n') - sys.exit (1) - - # system parameters - f=trellis.fsm(fname) # get the FSM specification from a file (will hopefully be automated in the future...) - Kb=1024*16 # packet size in bits (make it multiple of 16) - bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol - K=Kb/bitspersymbol # packet size in trellis steps - modulation = fsm_utils.psk4 # see fsm_utils.py for available predefined modulations - dimensionality = modulation[0] - constellation = modulation[1] - if len(constellation)/dimensionality != f.O(): - sys.stderr.write ('Incompatible FSM output cardinality and modulation size.\n') - sys.exit (1) - # calculate average symbol energy - Es = 0 - for i in range(len(constellation)): - Es = Es + constellation[i]**2 - Es = Es / (len(constellation)/dimensionality) - N0=Es/pow(10.0,esn0_db/10.0); # noise variance - - tot_s=0 # total number of transmitted shorts - terr_s=0 # total number of shorts in error - terr_p=0 # total number of packets in error - for i in range(rep): - (s,e)=run_test(f,Kb,bitspersymbol,K,dimensionality,constellation,N0,-long(666+i)) # run experiment with different seed to get different noise realizations - tot_s=tot_s+s - terr_s=terr_s+e - terr_p=terr_p+(terr_s!=0) - if ((i+1)%100==0) : # display progress - print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - # estimate of the (short or bit) error rate - print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - - - -if __name__ == '__main__': - main (sys.argv[1:]) - diff --git a/gnuradio-examples/python/channel-coding/test_tcm_parallel.py b/gnuradio-examples/python/channel-coding/test_tcm_parallel.py deleted file mode 100755 index f9dcb58526..0000000000 --- a/gnuradio-examples/python/channel-coding/test_tcm_parallel.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import audio -from gnuradio import trellis -from gnuradio import eng_notation -import math -import sys -import fsm_utils - -def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed,P): - fg = gr.flow_graph () - - # TX - src = gr.lfsr_32k_source_s() - src_head = gr.head (gr.sizeof_short,Kb/16*P) # packet size in shorts - s2fsmi=gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality - s2p = gr.stream_to_streams(gr.sizeof_short,P) # serial to parallel - enc = trellis.encoder_ss(f,0) # initiali state = 0 - mod = gr.chunks_to_symbols_sf(constellation,dimensionality) - - # CHANNEL - add=[] - noise=[] - for i in range(P): - add.append(gr.add_ff()) - noise.append(gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)) - - # RX - metrics = trellis.metrics_f(f.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi - va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set. - p2s = gr.streams_to_stream(gr.sizeof_short,P) # parallel to serial - fsmi2s=gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = gr.check_lfsr_32k_s() - - fg.connect (src,src_head,s2fsmi,s2p) - for i in range(P): - fg.connect ((s2p,i),(enc,i),(mod,i)) - fg.connect ((mod,i),(add[i],0)) - fg.connect (noise[i],(add[i],1)) - fg.connect (add[i],(metrics,i)) - fg.connect ((metrics,i),(va,i),(p2s,i)) - fg.connect (p2s,fsmi2s,dst) - - - fg.run() - - # A bit of cheating: run the program once and print the - # final encoder state. - # Then put it as the last argument in the viterbi block - #print "final state = " , enc.ST() - - ntotal = dst.ntotal () - nright = dst.nright () - runlength = dst.runlength () - - return (ntotal,ntotal-nright) - - - -def main(args): - nargs = len (args) - if nargs == 3: - fname=args[0] - esn0_db=float(args[1]) # Es/No in dB - rep=int(args[2]) # number of times the experiment is run to collect enough errors - else: - sys.stderr.write ('usage: test_tcm.py fsm_fname Es/No_db repetitions\n') - sys.exit (1) - - # system parameters - f=trellis.fsm(fname) # get the FSM specification from a file - P=4 # how many parallel streams? - Kb=1024*16 # packet size in bits (make it multiple of 16 so it can be packed in a short) - bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol - K=Kb/bitspersymbol # packet size in trellis steps - modulation = fsm_utils.psk4 # see fsm_utlis.py for available predefined modulations - dimensionality = modulation[0] - constellation = modulation[1] - if len(constellation)/dimensionality != f.O(): - sys.stderr.write ('Incompatible FSM output cardinality and modulation size.\n') - sys.exit (1) - # calculate average symbol energy - Es = 0 - for i in range(len(constellation)): - Es = Es + constellation[i]**2 - Es = Es / (len(constellation)/dimensionality) - N0=Es/pow(10.0,esn0_db/10.0); # calculate noise variance - - tot_s=0 # total number of transmitted shorts - terr_s=0 # total number of shorts in error - terr_p=0 # total number of packets in error - for i in range(rep): - (s,e)=run_test(f,Kb,bitspersymbol,K,dimensionality,constellation,N0,-long(666+i),P) # run experiment with different seed to get different noise realizations - tot_s=tot_s+s - terr_s=terr_s+e - terr_p=terr_p+(terr_s!=0) - if ((i+1)%100==0) : # display progress - print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - # estimate of the (short or bit) error rate - print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - - -if __name__ == '__main__': - main (sys.argv[1:]) - diff --git a/gnuradio-examples/python/channel-coding/test_turbo_equalization.py b/gnuradio-examples/python/channel-coding/test_turbo_equalization.py deleted file mode 100755 index ff0497e2b0..0000000000 --- a/gnuradio-examples/python/channel-coding/test_turbo_equalization.py +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import audio -from gnuradio import trellis -from gnuradio import eng_notation -import math -import sys -import fsm_utils - - -def make_rx(fg,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,type): - metrics_in = trellis.metrics_f(fi.O(),dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner SISO - scale = gr.multiply_const_ff(1.0/N0) - gnd = gr.vector_source_f([0],True); - - inter=[] - deinter=[] - siso_in=[] - siso_out=[] - - # generate all blocks - for it in range(IT): - inter.append( trellis.permutation(interleaver.K(),interleaver.INTER(),fi.I(),gr.sizeof_float) ) - siso_in.append( trellis.siso_f(fi,K,0,-1,True,False,type) ) - deinter.append( trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float) ) - if it < IT-1: - siso_out.append( trellis.siso_f(fo,K,0,-1,False,True,type) ) - else: - siso_out.append( trellis.viterbi_s(fo,K,0,-1) ) # no soft outputs needed - - # connect first stage - fg.connect (gnd,inter[0]) - fg.connect (metrics_in,scale) - fg.connect (scale,(siso_in[0],1)) - - # connect the rest - for it in range(IT): - if it < IT-1: - fg.connect (metrics_in,(siso_in[it+1],1)) - fg.connect (siso_in[it],deinter[it],(siso_out[it],1)) - fg.connect (gnd,(siso_out[it],0)) - fg.connect (siso_out[it],inter[it+1]) - fg.connect (inter[it],(siso_in[it],0)) - else: - fg.connect (siso_in[it],deinter[it],siso_out[it]) - fg.connect (inter[it],(siso_in[it],0)) - - return (metrics_in,siso_out[IT-1]) - - -def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,tot_constellation,Es,N0,IT,seed): - fg = gr.flow_graph () - - # TX - src = gr.lfsr_32k_source_s() - src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the iouter FSM input cardinality - enc_out = trellis.encoder_ss(fo,0) # initial state = 0 - inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short) - enc_in = trellis.encoder_ss(fi,0) # initial state = 0 - # essentially here we implement the combination of modulation and channel as a memoryless modulation (the memory induced by the channel is hidden in the innner FSM) - mod = gr.chunks_to_symbols_sf(tot_constellation,dimensionality) - - # CHANNEL - add = gr.add_ff() - noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) - - # RX - (head,tail) = make_rx(fg,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM) - fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = gr.check_lfsr_32k_s(); - - fg.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod) - fg.connect (mod,(add,0)) - fg.connect (noise,(add,1)) - fg.connect (add,head) - fg.connect (tail,fsmi2s,dst) - - fg.run() - - ntotal = dst.ntotal () - nright = dst.nright () - runlength = dst.runlength () - #print ntotal,nright,runlength - - return (ntotal,ntotal-nright) - - - - -def main(args): - nargs = len (args) - if nargs == 3: - fname_out=args[0] - esn0_db=float(args[1]) - rep=int(args[2]) - else: - sys.stderr.write ('usage: test_turbo_equalization.py fsm_name_out Es/No_db repetitions\n') - sys.exit (1) - - # system parameters - Kb=64*16 # packet size in bits (multiple of 16) - modulation = fsm_utils.pam4 # see fsm_utlis.py for available predefined modulations - channel = fsm_utils.c_channel # see fsm_utlis.py for available predefined test channels - fo=trellis.fsm(fname_out) # get the outer FSM specification from a file - fi=trellis.fsm(len(modulation[1]),len(channel)) # generate the FSM automatically - if fo.O() != fi.I(): - sys.stderr.write ('Incompatible cardinality between outer and inner FSM.\n') - sys.exit (1) - bitspersymbol = int(round(math.log(fo.I())/math.log(2))) # bits per FSM input symbol - K=Kb/bitspersymbol # packet size in trellis steps - print 'size = ',K - interleaver=trellis.interleaver(K,666) # construct a random interleaver - tot_channel = fsm_utils.make_isi_lookup(modulation,channel,True) # generate the lookup table (normalize energy to 1) - dimensionality = tot_channel[0] - tot_constellation = tot_channel[1] - if len(tot_constellation)/dimensionality != fi.O(): - sys.stderr.write ('Incompatible FSM output cardinality and lookup table size.\n') - sys.exit (1) - N0=pow(10.0,-esn0_db/10.0); # noise variance - IT = 3 # number of turbo iterations - - tot_s=0 # total number of transmitted shorts - terr_s=0 # total number of shorts in error - terr_p=0 # total number of packets in error - - for i in range(rep): - (s,e)=run_test(fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,tot_constellation,1,N0,IT,-long(666+i)) # run experiment with different seed to get different noise realizations - print s - tot_s=tot_s+s - terr_s=terr_s+e - terr_p=terr_p+(terr_s!=0) - if ((i+1)%10==0) : # display progress - print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - # estimate of the (short or bit) error rate - print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - - - -if __name__ == '__main__': - main (sys.argv[1:]) - diff --git a/gnuradio-examples/python/channel-coding/test_turbo_equalization1.py b/gnuradio-examples/python/channel-coding/test_turbo_equalization1.py deleted file mode 100755 index 5afd5ba66e..0000000000 --- a/gnuradio-examples/python/channel-coding/test_turbo_equalization1.py +++ /dev/null @@ -1,147 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import audio -from gnuradio import trellis -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -def make_rx(fg,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,type): - metrics_in = trellis.metrics_f(fi.O(),dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner SISO - scale = gr.multiply_const_ff(1.0/N0) - gnd = gr.vector_source_f([0],True); - - inter=[] - deinter=[] - siso_in=[] - siso_out=[] - - # generate all blocks - for it in range(IT): - inter.append( trellis.permutation(interleaver.K(),interleaver.INTER(),fi.I(),gr.sizeof_float) ) - siso_in.append( trellis.siso_f(fi,K,0,-1,True,False,type) ) - deinter.append( trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float) ) - if it < IT-1: - siso_out.append( trellis.siso_f(fo,K,0,-1,False,True,type) ) - else: - siso_out.append( trellis.viterbi_s(fo,K,0,-1) ) # no soft outputs needed - - # connect first stage - fg.connect (gnd,inter[0]) - fg.connect (metrics_in,scale) - fg.connect (scale,(siso_in[0],1)) - - # connect the rest - for it in range(IT): - if it < IT-1: - fg.connect (scale,(siso_in[it+1],1)) - fg.connect (siso_in[it],deinter[it],(siso_out[it],1)) - fg.connect (gnd,(siso_out[it],0)) - fg.connect (siso_out[it],inter[it+1]) - fg.connect (inter[it],(siso_in[it],0)) - else: - fg.connect (siso_in[it],deinter[it],siso_out[it]) - fg.connect (inter[it],(siso_in[it],0)) - - return (metrics_in,siso_out[IT-1]) - - -def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,Es,N0,IT,seed): - fg = gr.flow_graph () - L = len(channel) - - # TX - # this for loop is TOO slow in python!!! - packet = [0]*(K) - random.seed(seed) - for i in range(len(packet)): - packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols - src = gr.vector_source_s(packet,False) - enc_out = trellis.encoder_ss(fo,0) # initial state = 0 - inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short) - mod = gr.chunks_to_symbols_sf(modulation[1],modulation[0]) - - # CHANNEL - isi = gr.fir_filter_fff(1,channel) - add = gr.add_ff() - noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) - - # RX - (head,tail) = make_rx(fg,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM) - dst = gr.vector_sink_s(); - - fg.connect (src,enc_out,inter,mod) - fg.connect (mod,isi,(add,0)) - fg.connect (noise,(add,1)) - fg.connect (add,head) - fg.connect (tail,dst) - - fg.run() - - data = dst.data() - ntotal = len(data) - nright=0 - for i in range(ntotal): - if packet[i]==data[i]: - nright=nright+1 - #else: - #print "Error in ", i - - return (ntotal,ntotal-nright) - - - - -def main(args): - nargs = len (args) - if nargs == 3: - fname_out=args[0] - esn0_db=float(args[1]) - rep=int(args[2]) - else: - sys.stderr.write ('usage: test_turbo_equalization.py fsm_name_out Es/No_db repetitions\n') - sys.exit (1) - - # system parameters - Kb=64*16 # packet size in bits (multiple of 16) - modulation = fsm_utils.pam4 # see fsm_utlis.py for available predefined modulations - channel = fsm_utils.c_channel # see fsm_utlis.py for available predefined test channels - fo=trellis.fsm(fname_out) # get the outer FSM specification from a file - fi=trellis.fsm(len(modulation[1]),len(channel)) # generate the FSM automatically - if fo.O() != fi.I(): - sys.stderr.write ('Incompatible cardinality between outer and inner FSM.\n') - sys.exit (1) - bitspersymbol = int(round(math.log(fo.I())/math.log(2))) # bits per FSM input symbol - K=Kb/bitspersymbol # packet size in trellis steps - interleaver=trellis.interleaver(K,666) # construct a random interleaver - tot_channel = fsm_utils.make_isi_lookup(modulation,channel,True) # generate the lookup table (normalize energy to 1) - dimensionality = tot_channel[0] - tot_constellation = tot_channel[1] - if len(tot_constellation)/dimensionality != fi.O(): - sys.stderr.write ('Incompatible FSM output cardinality and lookup table size.\n') - sys.exit (1) - N0=pow(10.0,-esn0_db/10.0); # noise variance - IT = 3 # number of turbo iterations - - tot_s=0 # total number of transmitted shorts - terr_s=0 # total number of shorts in error - terr_p=0 # total number of packets in error - - for i in range(rep): - (s,e)=run_test(fo,fi,interleaver,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,1,N0,IT,-long(666+i)) # run experiment with different seed to get different noise realizations - tot_s=tot_s+s - terr_s=terr_s+e - terr_p=terr_p+(terr_s!=0) - if ((i+1)%10==0) : # display progress - print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - # estimate of the (short or bit) error rate - print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - - - -if __name__ == '__main__': - main (sys.argv[1:]) - diff --git a/gnuradio-examples/python/channel-coding/test_turbo_equalization2.py b/gnuradio-examples/python/channel-coding/test_turbo_equalization2.py deleted file mode 100755 index 7e252d6d10..0000000000 --- a/gnuradio-examples/python/channel-coding/test_turbo_equalization2.py +++ /dev/null @@ -1,147 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import audio -from gnuradio import trellis -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -def make_rx(fg,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,type): - scale = gr.multiply_const_ff(math.sqrt(1.0/N0)) - gnd = gr.vector_source_f([0],True); - - inter=[] - deinter=[] - siso_in=[] - siso_out=[] - - # generate all blocks - for it in range(IT): - inter.append( trellis.permutation(interleaver.K(),interleaver.INTER(),fi.I(),gr.sizeof_float) ) - siso_in.append( trellis.siso_combined_f(fi,K,0,-1,True,False,type,dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) ) - deinter.append( trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float) ) - if it < IT-1: - siso_out.append( trellis.siso_f(fo,K,0,-1,False,True,type) ) - else: - siso_out.append( trellis.viterbi_s(fo,K,0,-1) ) # no soft outputs needed - - # connect first stage - fg.connect (gnd,inter[0]) - fg.connect (scale,(siso_in[0],1)) - - # connect the rest - for it in range(IT): - if it < IT-1: - fg.connect (scale,(siso_in[it+1],1)) - fg.connect (siso_in[it],deinter[it],(siso_out[it],1)) - fg.connect (gnd,(siso_out[it],0)) - fg.connect (siso_out[it],inter[it+1]) - fg.connect (inter[it],(siso_in[it],0)) - else: - fg.connect (siso_in[it],deinter[it],siso_out[it]) - fg.connect (inter[it],(siso_in[it],0)) - - return (scale,siso_out[IT-1]) - - -def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,Es,N0,IT,seed): - fg = gr.flow_graph () - L = len(channel) - - # TX - # this for loop is TOO slow in python!!! - packet = [0]*(K) - random.seed(seed) - for i in range(len(packet)): - packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols - src = gr.vector_source_s(packet,False) - enc_out = trellis.encoder_ss(fo,0) # initial state = 0 - inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short) - mod = gr.chunks_to_symbols_sf(modulation[1],modulation[0]) - - # CHANNEL - isi = gr.fir_filter_fff(1,channel) - add = gr.add_ff() - noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) - - # RX - (head,tail) = make_rx(fg,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM) - dst = gr.vector_sink_s(); - - fg.connect (src,enc_out,inter,mod) - fg.connect (mod,isi,(add,0)) - fg.connect (noise,(add,1)) - fg.connect (add,head) - fg.connect (tail,dst) - - fg.run() - - data = dst.data() - ntotal = len(data) - nright=0 - for i in range(ntotal): - if packet[i]==data[i]: - nright=nright+1 - #else: - #print "Error in ", i - - return (ntotal,ntotal-nright) - - - - -def main(args): - nargs = len (args) - if nargs == 3: - fname_out=args[0] - esn0_db=float(args[1]) - rep=int(args[2]) - else: - sys.stderr.write ('usage: test_turbo_equalization.py fsm_name_out Es/No_db repetitions\n') - sys.exit (1) - - # system parameters - Kb=64*16 # packet size in bits (multiple of 16) - modulation = fsm_utils.pam4 # see fsm_utlis.py for available predefined modulations - channel = fsm_utils.c_channel # see fsm_utlis.py for available predefined test channels - fo=trellis.fsm(fname_out) # get the outer FSM specification from a file - fi=trellis.fsm(len(modulation[1]),len(channel)) # generate the FSM automatically - if fo.O() != fi.I(): - sys.stderr.write ('Incompatible cardinality between outer and inner FSM.\n') - sys.exit (1) - bitspersymbol = int(round(math.log(fo.I())/math.log(2))) # bits per FSM input symbol - K=Kb/bitspersymbol # packet size in trellis steps - interleaver=trellis.interleaver(K,666) # construct a random interleaver - tot_channel = fsm_utils.make_isi_lookup(modulation,channel,True) # generate the lookup table (normalize energy to 1) - dimensionality = tot_channel[0] - N0=pow(10.0,-esn0_db/10.0); # noise variance - tot_constellation =[0]*len(tot_channel[1]) - for i in range(len(tot_channel[1])): - tot_constellation[i] = tot_channel[1][i] * math.sqrt(1.0/N0) - if len(tot_constellation)/dimensionality != fi.O(): - sys.stderr.write ('Incompatible FSM output cardinality and lookup table size.\n') - sys.exit (1) - IT = 3 # number of turbo iterations - - tot_s=0 # total number of transmitted shorts - terr_s=0 # total number of shorts in error - terr_p=0 # total number of packets in error - - for i in range(rep): - (s,e)=run_test(fo,fi,interleaver,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,1,N0,IT,-long(666+i)) # run experiment with different seed to get different noise realizations - tot_s=tot_s+s - terr_s=terr_s+e - terr_p=terr_p+(terr_s!=0) - if ((i+1)%10==0) : # display progress - print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - # estimate of the (short or bit) error rate - print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - - - -if __name__ == '__main__': - main (sys.argv[1:]) - diff --git a/gnuradio-examples/python/channel-coding/test_viterbi_equalization.py b/gnuradio-examples/python/channel-coding/test_viterbi_equalization.py deleted file mode 100755 index 24545e3b0d..0000000000 --- a/gnuradio-examples/python/channel-coding/test_viterbi_equalization.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import audio -from gnuradio import trellis -from gnuradio import eng_notation -import math -import sys -import fsm_utils - -def run_test (f,Kb,bitspersymbol,K,dimensionality,tot_constellation,N0,seed): - fg = gr.flow_graph () - - # TX - src = gr.lfsr_32k_source_s() - src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality - enc = trellis.encoder_ss(f,0) # initial state = 0 - # essentially here we implement the combination of modulation and channel as a memoryless modulation (the memory induced by the channel is hidden in the FSM) - mod = gr.chunks_to_symbols_sf(tot_constellation,dimensionality) - - # CHANNEL - add = gr.add_ff() - noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) - - # RX - metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi - va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set. - fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = gr.check_lfsr_32k_s(); - - fg.connect (src,src_head,s2fsmi,enc,mod) - fg.connect (mod,(add,0)) - fg.connect (noise,(add,1)) - fg.connect (add,metrics) - fg.connect (metrics,va,fsmi2s,dst) - - fg.run() - - ntotal = dst.ntotal () - nright = dst.nright () - runlength = dst.runlength () - #print ntotal,nright,runlength - - return (ntotal,ntotal-nright) - - - - -def main(args): - nargs = len (args) - if nargs == 2: - esn0_db=float(args[0]) - rep=int(args[1]) - else: - sys.stderr.write ('usage: test_viterbi_equalization.py Es/No_db repetitions\n') - sys.exit (1) - - # system parameters - Kb=128*16 # packet size in bits (multiple of 16) - modulation = fsm_utils.pam4 # see fsm_utlis.py for available predefined modulations - channel = fsm_utils.c_channel # see fsm_utlis.py for available predefined test channels - f=trellis.fsm(len(modulation[1]),len(channel)) # generate the FSM automatically - bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol - K=Kb/bitspersymbol # packet size in trellis steps - - tot_channel = fsm_utils.make_isi_lookup(modulation,channel,True) # generate the lookup table (normalize energy to 1) - dimensionality = tot_channel[0] - tot_constellation = tot_channel[1] - N0=pow(10.0,-esn0_db/10.0); # noise variance - if len(tot_constellation)/dimensionality != f.O(): - sys.stderr.write ('Incompatible FSM output cardinality and lookup table size.\n') - sys.exit (1) - - - tot_s=0 # total number of transmitted shorts - terr_s=0 # total number of shorts in error - terr_p=0 # total number of packets in error - - for i in range(rep): - (s,e)=run_test(f,Kb,bitspersymbol,K,dimensionality,tot_constellation,N0,-long(666+i)) # run experiment with different seed to get different noise realizations - tot_s=tot_s+s - terr_s=terr_s+e - terr_p=terr_p+(terr_s!=0) - if ((i+1)%100==0) : # display progress - print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - # estimate of the (short or bit) error rate - print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - - - -if __name__ == '__main__': - main (sys.argv[1:]) - diff --git a/gnuradio-examples/python/channel-coding/test_viterbi_equalization1.py b/gnuradio-examples/python/channel-coding/test_viterbi_equalization1.py deleted file mode 100755 index 002d41a767..0000000000 --- a/gnuradio-examples/python/channel-coding/test_viterbi_equalization1.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import audio -from gnuradio import trellis -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -def run_test (f,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,N0,seed): - fg = gr.flow_graph () - L = len(channel) - - # TX - # this for loop is TOO slow in python!!! - packet = [0]*(K+2*L) - random.seed(seed) - for i in range(len(packet)): - packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols - for i in range(L): # first/last L symbols set to 0 - packet[i] = 0 - packet[len(packet)-i-1] = 0 - src = gr.vector_source_s(packet,False) - mod = gr.chunks_to_symbols_sf(modulation[1],modulation[0]) - - # CHANNEL - isi = gr.fir_filter_fff(1,channel) - add = gr.add_ff() - noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) - - # RX - skip = gr.skiphead(gr.sizeof_float, L) # skip the first L samples since you know they are coming from the L zero symbols - #metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi - #va = trellis.viterbi_s(f,K+L,-1,0) # Put -1 if the Initial/Final states are not set. - va = trellis.viterbi_combined_fs(f,K+L,0,0,dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # using viterbi_combined_fs instead of metrics_f/viterbi_s allows larger packet lengths because metrics_f is complaining for not being able to allocate large buffers. This is due to the large f.O() in this application... - dst = gr.vector_sink_s() - - fg.connect (src,mod) - fg.connect (mod,isi,(add,0)) - fg.connect (noise,(add,1)) - #fg.connect (add,metrics) - #fg.connect (metrics,va,dst) - fg.connect (add,skip,va,dst) - - fg.run() - - data = dst.data() - ntotal = len(data) - L - nright=0 - for i in range(ntotal): - if packet[i+L]==data[i]: - nright=nright+1 - #else: - #print "Error in ", i - - return (ntotal,ntotal-nright) - - -def main(args): - nargs = len (args) - if nargs == 2: - esn0_db=float(args[0]) - rep=int(args[1]) - else: - sys.stderr.write ('usage: test_viterbi_equalization1.py Es/No_db repetitions\n') - sys.exit (1) - - # system parameters - Kb=128*16 # packet size in bits (multiple of 16) - modulation = fsm_utils.pam4 # see fsm_utlis.py for available predefined modulations - channel = fsm_utils.c_channel # see fsm_utlis.py for available predefined test channels - f=trellis.fsm(len(modulation[1]),len(channel)) # generate the FSM automatically - bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol - K=Kb/bitspersymbol # packet size in trellis steps - - tot_channel = fsm_utils.make_isi_lookup(modulation,channel,True) # generate the lookup table (normalize energy to 1) - dimensionality = tot_channel[0] - tot_constellation = tot_channel[1] - N0=pow(10.0,-esn0_db/10.0); # noise variance - if len(tot_constellation)/dimensionality != f.O(): - sys.stderr.write ('Incompatible FSM output cardinality and lookup table size.\n') - sys.exit (1) - - tot_s=0 # total number of transmitted shorts - terr_s=0 # total number of shorts in error - terr_p=0 # total number of packets in error - - for i in range(rep): - (s,e)=run_test(f,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,N0,-long(666+i)) # run experiment with different seed to get different noise realizations - tot_s=tot_s+s - terr_s=terr_s+e - terr_p=terr_p+(terr_s!=0) - if ((i+1)%100==0) : # display progress - print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - # estimate of the (short or symbol) error rate - print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s) - - - -if __name__ == '__main__': - main (sys.argv[1:]) diff --git a/gnuradio-examples/python/digital/Makefile.am b/gnuradio-examples/python/digital/Makefile.am index 91b914dfd9..1db2f8470c 100644 --- a/gnuradio-examples/python/digital/Makefile.am +++ b/gnuradio-examples/python/digital/Makefile.am @@ -19,6 +19,8 @@ # Boston, MA 02110-1301, USA. # +include $(top_srcdir)/Makefile.common + EXTRA_DIST = \ README \ benchmark_rx.py \ @@ -32,3 +34,6 @@ EXTRA_DIST = \ transmit_path.py \ tunnel.py \ tx_voice.py + +ourdatadir = $(exampledir)/digital +ourdata_DATA = $(EXTRA_DIST) diff --git a/gnuradio-examples/python/digital_voice/Makefile.am b/gnuradio-examples/python/digital_voice/Makefile.am index 0236fbf214..08bd48821d 100644 --- a/gnuradio-examples/python/digital_voice/Makefile.am +++ b/gnuradio-examples/python/digital_voice/Makefile.am @@ -19,6 +19,11 @@ # Boston, MA 02110-1301, USA. # +include $(top_srcdir)/Makefile.common + EXTRA_DIST = \ encdec.py \ cvsd_test.py + +ourdatadir = $(exampledir)/digital_voice +ourdata_DATA = $(EXTRA_DIST) \ No newline at end of file diff --git a/gnuradio-examples/python/multi-antenna/Makefile.am b/gnuradio-examples/python/multi-antenna/Makefile.am index 0172eac359..7e620b3ab6 100644 --- a/gnuradio-examples/python/multi-antenna/Makefile.am +++ b/gnuradio-examples/python/multi-antenna/Makefile.am @@ -19,7 +19,12 @@ # Boston, MA 02110-1301, USA. # +include $(top_srcdir)/Makefile.common + EXTRA_DIST = \ multi_fft.py \ multi_file.py \ multi_scope.py + +ourdatadir = $(exampledir)/multi-antenna +ourdata_DATA = $(EXTRA_DIST) diff --git a/gnuradio-examples/python/multi_usrp/Makefile.am b/gnuradio-examples/python/multi_usrp/Makefile.am index 1f51f23a8a..01119bb8a7 100644 --- a/gnuradio-examples/python/multi_usrp/Makefile.am +++ b/gnuradio-examples/python/multi_usrp/Makefile.am @@ -19,10 +19,12 @@ # Boston, MA 02110-1301, USA. # -EXTRA_DIST = \ - README \ - multi_usrp_oscope.py \ - multi_usrp_rx_cfile.py - +include $(top_srcdir)/Makefile.common +EXTRA_DIST = \ + README \ + multi_usrp_oscope.py \ + multi_usrp_rx_cfile.py +ourdatadir = $(exampledir)/multi_usrp +ourdata_DATA = $(EXTRA_DIST) diff --git a/gnuradio-examples/python/ofdm/Makefile.am b/gnuradio-examples/python/ofdm/Makefile.am index 5e8570d698..e9ff3bacac 100644 --- a/gnuradio-examples/python/ofdm/Makefile.am +++ b/gnuradio-examples/python/ofdm/Makefile.am @@ -19,6 +19,8 @@ # Boston, MA 02110-1301, USA. # +include $(top_srcdir)/Makefile.common + EXTRA_DIST = \ benchmark_ofdm.py \ benchmark_ofdm_rx.py \ @@ -28,3 +30,6 @@ EXTRA_DIST = \ pick_bitrate.py \ receive_path.py \ transmit_path.py + +ourdatadir = $(exampledir)/ofdm +ourdata_DATA = $(EXTRA_DIST) diff --git a/gnuradio-examples/python/usrp/Makefile.am b/gnuradio-examples/python/usrp/Makefile.am index 0d82031c6f..71f4607213 100644 --- a/gnuradio-examples/python/usrp/Makefile.am +++ b/gnuradio-examples/python/usrp/Makefile.am @@ -19,30 +19,14 @@ # Boston, MA 02110-1301, USA. # +include $(top_srcdir)/Makefile.common + EXTRA_DIST = \ - am_rcv.py \ - ayfabtu.py \ - benchmark_usb.py \ - flexrf_debug.py \ - flexrf_siggen.py \ fm_tx_2_daughterboards.py \ fm_tx4.py \ max_power.py \ - siggen_min2.py \ - test_counting.py \ - test_dft_analysis.py \ - test_dft_synth.py \ - test_digital_loopback_counting.py \ - test_digital_loopback_lfsr.py \ - tvrx_am_rcv_gui.py \ - usrp_fft_old.py \ - usrp_fft.py \ usrp_nbfm_ptt.py \ usrp_nbfm_rcv.py \ - usrp_oscope.py \ - usrp_rx_cfile.py \ - usrp_rx_nogui.py \ - usrp_siggen.py \ usrp_spectrum_sense.py \ usrp_tv_rcv_nogui.py \ usrp_tv_rcv.py \ @@ -53,3 +37,6 @@ EXTRA_DIST = \ usrp_wfm_rcv2_nogui.py \ usrp_wxapt_rcv.py \ wfm_rcv_file.py + +ourdatadir = $(exampledir)/usrp +ourdata_DATA = $(EXTRA_DIST) diff --git a/gnuradio-examples/python/usrp/am_rcv.py b/gnuradio-examples/python/usrp/am_rcv.py deleted file mode 100755 index 2908dcbf54..0000000000 --- a/gnuradio-examples/python/usrp/am_rcv.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr, eng_notation -from gnuradio import audio -from gnuradio import usrp -from gnuradio.eng_option import eng_option -from optparse import OptionParser -import sys -import math - -from gnuradio.wxgui import stdgui, fftsink -import wx - -class am_rx_graph (stdgui.gui_flow_graph): - def __init__(self,frame,panel,vbox,argv): - stdgui.gui_flow_graph.__init__ (self,frame,panel,vbox,argv) - - station = parseargs(argv[1:]) - offset_freq = 30e3 - IF_freq = offset_freq - station - - adc_rate = 64e6 - usrp_decim = 250 - if_rate = adc_rate / usrp_decim # 256 kHz - if_decim = 4 - demod_rate = if_rate / if_decim # 64 kHz - audio_decimation = 2 - audio_rate = demod_rate / audio_decimation # 16 kHz - - # usrp is data source - src = usrp.source_c (0, usrp_decim) - src.set_rx_freq (0, IF_freq) - actual_IF_freq =src.rx_freq(0) - actual_offset = actual_IF_freq + station - - #print actual_IF_freq - #print actual_offset - - src.set_pga(0,20) - # sound card as final sink - audio_sink = audio.sink (int (audio_rate)) - - channel_coeffs = \ - gr.firdes.low_pass (1.0, # gain - if_rate, # sampling rate - 9e3, # low pass cutoff freq - 10e3, # width of trans. band - gr.firdes.WIN_HANN) - - ddc = gr.freq_xlating_fir_filter_ccf (if_decim,channel_coeffs,-actual_offset,if_rate) - - magblock = gr.complex_to_mag() - volumecontrol = gr.multiply_const_ff(.003) - - # Deemphasis. Is this necessary on AM? - TAU = 75e-6 # 75us in US, 50us in EUR - fftaps = [ 1 - math.exp(-1/TAU/if_rate), 0] - fbtaps= [ 0 , math.exp(-1/TAU/if_rate) ] - - deemph = gr.iir_filter_ffd(fftaps,fbtaps) - - # compute FIR filter taps for audio filter - width_of_transition_band = audio_rate / 8 - audio_coeffs = gr.firdes.low_pass (1.0, # gain - if_rate, # sampling rate - 9e3, #audio_rate/2 - width_of_transition_band, - 4e3, # width_of_transition_band, - gr.firdes.WIN_HANN) - - # input: float; output: float - audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs) - - - - - print len(channel_coeffs) - print len(audio_coeffs) - - # now wire it all together - self.connect (src, ddc) - self.connect (ddc, magblock) - self.connect (magblock, volumecontrol) - self.connect (volumecontrol,deemph) - self.connect (deemph,audio_filter) - self.connect (audio_filter, (audio_sink, 0)) - - if 1: - pre_demod = fftsink.fft_sink_c (self, panel, title="Pre-Demodulation", fft_size=128, sample_rate=if_rate) - self.connect (src, pre_demod) - vbox.Add (pre_demod.win, 1, wx.EXPAND) - - if 0: - post_demod = fftsink.fft_sink_c (self, panel, title="Post Demodulation", fft_size=256, sample_rate=demod_rate) - self.connect (ddc, post_demod) - vbox.Add (post_demod.win, 1, wx.EXPAND) - - if 0: - post_filt = fftsink.fft_sink_f (self, panel, title="Post Filter", fft_size=512, sample_rate=audio_rate) - self.connect (magblock,post_filt) - vbox.Add (post_filt.win, 1, wx.EXPAND) - -def parseargs (args): - nargs = len (args) - if nargs == 1: - freq1 = float (args[0]) * 1e3 - else: - sys.stderr.write ('usage: am_rcv freq1\n') - sys.exit (1) - - return freq1 - -if __name__ == '__main__': - app = stdgui.stdapp (am_rx_graph, "AM RX") - app.MainLoop () - diff --git a/gnuradio-examples/python/usrp/ayfabtu.dat b/gnuradio-examples/python/usrp/ayfabtu.dat deleted file mode 100644 index 5c65cf4833..0000000000 Binary files a/gnuradio-examples/python/usrp/ayfabtu.dat and /dev/null differ diff --git a/gnuradio-examples/python/usrp/ayfabtu.py b/gnuradio-examples/python/usrp/ayfabtu.py deleted file mode 100755 index de6c26f58a..0000000000 --- a/gnuradio-examples/python/usrp/ayfabtu.py +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2005 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -# -# All Your Frequencies are Belong to Us! -# -# Transmit NBFM message on 25 channels simultaneously! -# - -from gnuradio import gr, gru, eng_notation -from gnuradio import usrp -from gnuradio import audio -from gnuradio import blks -from gnuradio import optfir -from gnuradio.eng_option import eng_option -from optparse import OptionParser -import math -import sys -import random - -from gnuradio.wxgui import stdgui, fftsink -import wx - - -def make_random_complex_tuple(L): - result = [] - for x in range(L): - result.append(complex(random.gauss(0, 1),random.gauss(0, 1))) - - return tuple(result) - -def random_noise_c(): - src = gr.vector_source_c(make_random_complex_tuple(32*1024), True) - return src - - -def plot_taps(taps, sample_rate=2): - return gru.gnuplot_freqz (gru.freqz (taps, 1), sample_rate) - - -class ayfabtu_graph (stdgui.gui_flow_graph): - def __init__(self, frame, panel, vbox, argv): - stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv) - - parser = OptionParser (option_class=eng_option) - parser.add_option ("-c", "--duc-freq", type="eng_float", default=29.325e6, - help="set Tx ddc frequency to FREQ", metavar="FREQ") - (options, args) = parser.parse_args () - - nchan = 25 - IF_GAIN = 80000 - AUDIO_GAIN = 100 - - self.dac_rate = 128e6 - self.usrp_interp = 256 - self.usrp_rate = self.dac_rate / self.usrp_interp # 500 kS/s - self.audio_rate = 32000 # 32 kS/s - - self.audio_src = gr.file_source(gr.sizeof_float, "ayfabtu.dat", True) - - ahp_taps = gr.firdes.high_pass(1, # gain - 32e3, # Fs - 300, # cutoff - 600, # trans width - gr.firdes.WIN_HANN) - self.audio_hp = gr.fir_filter_fff(1, ahp_taps) - - self.audio_gain = gr.multiply_const_ff(AUDIO_GAIN) - - null_src = gr.null_source(gr.sizeof_gr_complex) - #noise_src = gr.noise_source_c(gr.GR_UNIFORM, 1, 0) - noise_src = random_noise_c() - - if 0: - artaps = optfir.low_pass(1, # gain - 2, # Fs - .75/32, # freq1 - 1.0/32, # freq2 - 1, # pb ripple in dB - 50, # stopband atten in dB - 2) # + extra taps - else: - artaps = gr.firdes.low_pass(1, # gain - 32e3*15,# Fs - 2.7e3, # cutoff - .3e3, # trans width - gr.firdes.WIN_HANN) - print "len(artaps) =", len(artaps) - self.audio_resampler = blks.rational_resampler_fff(self, 15, 32, artaps) - - self.fm_mod = blks.nbfm_tx(self, 15000, 15000, max_dev=4.5e3) - - - fbtaps = gr.firdes.low_pass(1, # gain - 25*15e3, # rate - 13e3, # cutoff - 2e3, # trans width - gr.firdes.WIN_HANN) - print "len(fbtabs) =", len(fbtaps) - #self.plot = plot_taps(fbtaps, 25*15e3) - self.filter_bank = blks.synthesis_filterbank(self, nchan, fbtaps) - - self.if_gain = gr.multiply_const_cc(IF_GAIN) - - if 0: - ifrtaps = optfir.low_pass(1, - 2, # Fs - .75/3, # freq1 - 1.0/3, # freq2 - 1, # pb ripple in dB - 50, # stopband atten in dB - 2) # + extra taps - else: - ifrtaps = gr.firdes.low_pass(1, - 2, # Fs - .75/3, # freq1 - .25/3, # trans width - gr.firdes.WIN_HANN) - - - print "len(ifrtaps) =", len(ifrtaps) - self.if_resampler = blks.rational_resampler_ccf(self, 4, 3, ifrtaps) - - - self.u = usrp.sink_c(0, 256) - self.u.set_tx_freq(0, options.duc_freq) - self.u.set_pga(0, self.u.pga_max()) - - # wire it all together - - self.connect(self.audio_src, self.audio_hp, self.audio_gain, - self.audio_resampler, self.fm_mod) - - null_sink = gr.null_sink(gr.sizeof_gr_complex) - - for i in range(nchan): - if True or i == 0: - self.connect(self.fm_mod, (self.filter_bank, i)) - else: - self.connect(null_src, (self.filter_bank, i)) - - self.connect(self.filter_bank, self.if_gain, self.if_resampler, self.u) - - -def main (): - app = stdgui.stdapp (ayfabtu_graph, "All Your Frequency Are Belong to Us") - app.MainLoop () - -if __name__ == '__main__': - main () diff --git a/gnuradio-examples/python/usrp/benchmark_usb.py b/gnuradio-examples/python/usrp/benchmark_usb.py deleted file mode 100755 index fc01514a13..0000000000 --- a/gnuradio-examples/python/usrp/benchmark_usb.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2005 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -""" -Benchmark the USB/USRP throughput. Finds the maximum full-duplex speed -the USRP/USB combination can sustain without errors. - -This program does not currently give reliable results. Sorry about that... -""" - -from gnuradio import gr -from gnuradio import usrp -from gnuradio import eng_notation - -import sys - -def run_test (usb_throughput, verbose): - # usb_throughput is in bytes/sec. - # - # Returns True or False - - nsec = 1 - stream_length = int (usb_throughput/2 * nsec) # length of stream to examine - - adc_freq = 64e6 - dac_freq = 128e6 - sizeof_sample = 2 * gr.sizeof_short - - usb_throughput_in_samples = usb_throughput / sizeof_sample - - # allocate usb throughput 50/50 between Tx and Rx - - tx_interp = int (dac_freq) / int (usb_throughput_in_samples / 2) - rx_decim = int (adc_freq) / int (usb_throughput_in_samples / 2) - - # print "tx_interp =", tx_interp, "rx_decim =", rx_decim - assert (tx_interp == 2 * rx_decim) - - fg = gr.flow_graph () - - # Build the Tx pipeline - data_src = gr.lfsr_32k_source_s () - src_head = gr.head (gr.sizeof_short, int (stream_length * 2)) - usrp_tx = usrp.sink_s (0, tx_interp) - fg.connect (data_src, src_head, usrp_tx) - - # and the Rx pipeline - usrp_rx = usrp.source_s (0, rx_decim, 1, 0x32103210, usrp.FPGA_MODE_LOOPBACK) - head = gr.head (gr.sizeof_short, stream_length) - check = gr.check_lfsr_32k_s () - fg.connect (usrp_rx, head, check) - - fg.run () - - ntotal = check.ntotal () - nright = check.nright () - runlength = check.runlength () - - if verbose: - print "usb_throughput =", eng_notation.num_to_str (usb_throughput) - print "ntotal =", ntotal - print "nright =", nright - print "runlength =", runlength - print "delta =", ntotal - runlength - - return runlength >= stream_length - 80000 - -def main (): - verbose = True - best_rate = 0 - usb_rate = [ 2e6, 4e6, 8e6, 16e6, 32e6 ] - #usb_rate = [ 32e6, 32e6, 32e6, 32e6, 32e6 ] - # usb_rate.reverse () - for rate in usb_rate: - sys.stdout.write ("Testing %sB/sec... " % (eng_notation.num_to_str (rate))) - sys.stdout.flush () - ok = run_test (rate, verbose) - if ok: - best_rate = max (best_rate, rate) - sys.stdout.write ("OK\n") - else: - sys.stdout.write ("FAILED\n") - - print "Max USB/USRP throughput = %sB/sec" % (eng_notation.num_to_str (best_rate),) - -if __name__ == '__main__': - main () diff --git a/gnuradio-examples/python/usrp/flexrf_debug.py b/gnuradio-examples/python/usrp/flexrf_debug.py deleted file mode 100755 index 13d1db110d..0000000000 --- a/gnuradio-examples/python/usrp/flexrf_debug.py +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from gnuradio import gr, gru -from gnuradio import usrp -from gnuradio import eng_notation -from gnuradio.eng_option import eng_option -from gnuradio.wxgui import stdgui, fftsink, scopesink, slider -from optparse import OptionParser -import wx - -class app_flow_graph (stdgui.gui_flow_graph): - def __init__(self, frame, panel, vbox, argv): - stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv) - - self.frame = frame - self.panel = panel - - parser = OptionParser (option_class=eng_option) - parser.add_option ("-d", "--decim", type="int", default=8, - help="set fgpa decimation rate to DECIM") - parser.add_option ("-c", "--ddc-freq", type="eng_float", default=0, - help="set Digital downconverter frequency to FREQ", metavar="FREQ") - parser.add_option ("-f", "--freq", type="eng_float", default=950e6, - help="set RF downconverter frequency to FREQ", metavar="FREQ") - parser.add_option ("-m", "--mux", type="intx", default=0x32103210, - help="set fpga FR_RX_MUX register to MUX") - parser.add_option ("-g", "--gain", type="eng_float", default=0, - help="set Rx PGA gain in dB (default 0 dB)") - (options, args) = parser.parse_args () - - self.u = usrp.source_c (0, options.decim, 1, gru.hexint(options.mux), 0) - - self.u.set_verbose (0) - - input_rate = self.u.adc_freq () / self.u.decim_rate () - - block = fftsink.fft_sink_c (self, panel, fft_size=1024, sample_rate=input_rate) - self.connect (self.u, block) - vbox.Add (block.win, 10, wx.EXPAND) - - if 0: - c2f_1 = gr.complex_to_float () - scope = scopesink.scope_sink_f (self, panel, "Rx Data", input_rate) - vbox.Add (scope.win, 6, wx.EXPAND) - - self.connect (self.u,c2f_1) - self.connect ((c2f_1, 0), (scope, 0)) - self.connect ((c2f_1, 1), (scope, 1)) - - if 0: - rms_complex = gr.rms_cf(.0001) - rms_i = gr.rms_ff(.0001) - rms_q = gr.rms_ff(.0001) - - self.connect(self.u,rms_complex) - self.connect((c2f_1,0),rms_i) - self.connect((c2f_1,1),rms_q) - - ns1 = gr.null_sink(4) - ns2 = gr.null_sink(4) - ns3 = gr.null_sink(4) - - self.connect(rms_complex,ns1) - self.connect(rms_i,ns2) - self.connect(rms_q,ns3) - - # sliders - - #vbox.Add(slider.slider(panel, 0, 104, self.set_gain), 1, wx.ALIGN_CENTER) - - #vbox.Add(slider.slider(panel, 0, 4095, self.set_gain_gc1), 1, wx.ALIGN_CENTER) - #vbox.Add(slider.slider(panel, 0, 31, self.set_gain_gc2), 1, wx.ALIGN_CENTER) - #vbox.Add(slider.slider(panel, 0, 1, self.set_gain_dl), 1, wx.ALIGN_CENTER) - #vbox.Add(slider.slider(panel, 0, 200, self.set_gain_i), 1, wx.ALIGN_CENTER) - #vbox.Add(slider.slider(panel, 0, 200, self.set_gain_q), 1, wx.ALIGN_CENTER) - - self.offset = 0 - #vbox.Add(slider.slider(panel, -200, 200, self.set_offset_i), 1, wx.ALIGN_CENTER) - #vbox.Add(slider.slider(panel, -200, 200, self.set_offset_q), 1, wx.ALIGN_CENTER) - - vbox.Add(slider.slider(panel, 380, 480, self.set_rf_freq), 1, wx.EXPAND|wx.ALIGN_CENTER) - vbox.Add(slider.slider(panel, -32000, +32000, self.set_if_freq), 1, wx.EXPAND|wx.ALIGN_CENTER) - vbox.Add(slider.slider(panel, 0, 4095, self.set_gain), 1, wx.EXPAND|wx.ALIGN_CENTER) - - # build small control area at bottom - hbox = wx.BoxSizer (wx.HORIZONTAL) - hbox.Add ((1, 1), 1, wx.EXPAND) - hbox.Add (wx.StaticText (panel, -1, "Set ddc freq: "), 0, wx.ALIGN_CENTER) - self.tc_freq = wx.TextCtrl (panel, -1, "", style=wx.TE_PROCESS_ENTER) - hbox.Add (self.tc_freq, 0, wx.ALIGN_CENTER) - wx.EVT_TEXT_ENTER (self.tc_freq, self.tc_freq.GetId(), self.handle_text_enter) - hbox.Add ((1, 1), 1, wx.EXPAND) - # add it to the main vbox - vbox.Add (hbox, 0, wx.EXPAND) - - self.update_status_bar () - - def set_rf_freq (self,freq): - (success,actual_freq) = self.set_freq(1e6*freq) - if not success: - print "Failed on ",freq - def set_if_freq (self,freq): - self.u.set_rx_freq(0,freq*1e3) - - def set_gain (self,gain): - self.rfrx.set_gain(gain) - - def set_gain_i (self,gain): - self.u.set_pga(0,gain/10.0) - def set_gain_q (self,gain): - self.u.set_pga(1,gain/10.0) - - def set_offset_i(self,offset): - self.offset = (self.offset & 0x0000ffff) | ((offset&0xffff)<<16) - self.u._write_fpga_reg (3,self.offset) - - def set_offset_q(self,offset): - self.offset = (self.offset & 0xffff0000) | (offset&0xffff) - self.u._write_fpga_reg (3,self.offset) - - def handle_text_enter (self, event): - str = event.GetString () - self.tc_freq.Clear () - self.u.set_rx_freq (0, eng_notation.str_to_num (str)) - self.update_status_bar () - - def update_status_bar (self): - ddc_freq = self.u.rx_freq (0) - decim_rate = self.u.decim_rate () - sample_rate = self.u.adc_freq () / decim_rate - msg = "decim: %d %sS/s DDC: %s" % ( - decim_rate, - eng_notation.num_to_str (sample_rate), - eng_notation.num_to_str (ddc_freq)) - - self.frame.GetStatusBar().SetStatusText (msg, 1) - - def set_gain(self,gain): - assert gain>=0 and gain<4096 - self.u.write_aux_dac(0,0,int(gain)) - -def main (): - app = stdgui.stdapp (app_flow_graph, "USRP FFT") - app.MainLoop () - -if __name__ == '__main__': - main () - - diff --git a/gnuradio-examples/python/usrp/flexrf_siggen.py b/gnuradio-examples/python/usrp/flexrf_siggen.py deleted file mode 100755 index 6a59148b88..0000000000 --- a/gnuradio-examples/python/usrp/flexrf_siggen.py +++ /dev/null @@ -1,148 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr, gru -from gnuradio import usrp -from gnuradio.eng_option import eng_option -from optparse import OptionParser -from gnuradio.wxgui import stdgui, slider -import wx - -class flex_siggen (stdgui.gui_flow_graph): - __slots__ = ['interp', 'waveform_type', 'waveform_ampl', - 'waveform_freq', 'waveform_offset', 'fg', 'usrp', - 'siggen', 'noisegen', 'src', 'file_sink' ] - - def __init__ (self,frame,panel,vbox,argv): - stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv) - - self.frame = frame - self.panel = panel - - parser = OptionParser (option_class=eng_option) - parser.add_option ("-a", "--amplitude", type="int", default=32000, - help="amplitude") - parser.add_option ("-i", "--interp", type="int", default=64, - help="set fpga interpolation rate to INTERP") - parser.add_option ("-n", "--nchannels", type="int", default=1, - help="set number of output channels to NCHANNELS") - (options, args) = parser.parse_args () - - self.waveform_type = gr.GR_CONST_WAVE - self.waveform_ampl = options.amplitude - self.waveform_freq = 100.12345e3 - self.waveform_offset = 0 - - self.interp = options.interp - self._instantiate_blocks () - self.usrp.set_nchannels (options.nchannels) - - self.dboard=self.usrp.db[0][0] - - self.set_waveform_type (self.waveform_type) - vbox.Add(slider.slider(panel, 390, 510, self.set_rf_freq), 1, wx.EXPAND|wx.ALIGN_CENTER) - vbox.Add(slider.slider(panel, -45000, +45000, self.set_if_freq), 1, wx.EXPAND|wx.ALIGN_CENTER) - #vbox.Add(slider.slider(panel, 0, 4095, self.set_gain), 1, wx.EXPAND|wx.ALIGN_CENTER) - - def usb_freq (self): - return self.usrp.dac_freq() / self.interp - - def usb_throughput (self): - return self.usb_freq () * 4 - - def set_waveform_type (self, type): - ''' - valid waveform types are: gr.GR_SIN_WAVE, gr.GR_CONST_WAVE, - gr.GR_UNIFORM and gr.GR_GAUSSIAN - ''' - self._configure_graph (type) - self.waveform_type = type - - def set_waveform_ampl (self, ampl): - self.waveform_ampl = ampl - self.siggen.set_amplitude (ampl) - self.noisegen.set_amplitude (ampl) - - def set_waveform_freq (self, freq): - self.waveform_freq = freq - self.siggen.set_frequency (freq) - - def set_if_freq (self, freq): - self.if_freq = freq - self.usrp.set_tx_freq (0,freq*1e3) - - def set_rf_freq (self, freq): - self.rf_freq = freq - (success,actual_freq) = self.dboard.set_freq (freq*1e6) - if not success: - print "Failed on ", freq - - def set_waveform_offset (self, offset): - self.waveform_offset = offset - self.siggen.set_offset (offset) - - def set_interpolator (self, interp): - self.interp = interp - self.siggen.set_sampling_freq (self.usb_freq ()) - self.usrp.set_interp_rate (interp) - - def set_duc_freq (self, freq): - self.usrp.set_tx_freq (0, freq) - - def _instantiate_blocks (self): - self.src = None - self.usrp = usrp.sink_c (0, self.interp) - - self.siggen = gr.sig_source_c (self.usb_freq (), - gr.GR_SIN_WAVE, - self.waveform_freq, - self.waveform_ampl, - self.waveform_offset) - - self.noisegen = gr.noise_source_c (gr.GR_UNIFORM, - self.waveform_ampl) - print "done" - - def _configure_graph (self, type): - was_running = self.is_running () - if was_running: - self.stop () - self.disconnect_all () - if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE: - self.connect (self.siggen, self.usrp) - self.siggen.set_waveform (type) - self.src = self.siggen - elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN: - self.connect (self.noisegen, self.usrp) - self.noisegen.set_type (type) - self.src = self.noisegen - else: - raise ValueError, type - if was_running: - self.start () - - -if __name__ == '__main__': - parser = OptionParser (option_class=eng_option) - parser.add_option ("--sine", dest="type", action="store_const", const=gr.GR_SIN_WAVE, - help="generate a complex sinusoid [default]", default=gr.GR_SIN_WAVE) - parser.add_option ("--const", dest="type", action="store_const", const=gr.GR_CONST_WAVE, - help="generate a constant output") - parser.add_option ("--gaussian", dest="type", action="store_const", const=gr.GR_GAUSSIAN, - help="generate Gaussian random output") - parser.add_option ("--uniform", dest="type", action="store_const", const=gr.GR_UNIFORM, - help="generate Uniform random output") - parser.add_option ("-f", "--freq", type="eng_float", default=100e3, - help="set waveform frequency to FREQ") - parser.add_option ("-r", "--rf-freq", type="eng_float", default=910e6, - help="set waveform frequency to FREQ") - parser.add_option ("-a", "--amplitude", type="eng_float", default=16e3, - help="set waveform amplitude to AMPLITUDE", metavar="AMPL") - parser.add_option ("-o", "--offset", type="eng_float", default=0, - help="set waveform offset to OFFSET") - parser.add_option ("-c", "--duc-freq", type="eng_float", default=0, - help="set Tx DUC frequency to FREQ", metavar="FREQ") - parser.add_option ("-m", "--mux", type="intx", default=0x98, - help="set output mux register") - - app = stdgui.stdapp (flex_siggen, "USRP FlexRF Siggen") - app.MainLoop () diff --git a/gnuradio-examples/python/usrp/limbo/am_rcv.py b/gnuradio-examples/python/usrp/limbo/am_rcv.py new file mode 100755 index 0000000000..2908dcbf54 --- /dev/null +++ b/gnuradio-examples/python/usrp/limbo/am_rcv.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python + +from gnuradio import gr, eng_notation +from gnuradio import audio +from gnuradio import usrp +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import sys +import math + +from gnuradio.wxgui import stdgui, fftsink +import wx + +class am_rx_graph (stdgui.gui_flow_graph): + def __init__(self,frame,panel,vbox,argv): + stdgui.gui_flow_graph.__init__ (self,frame,panel,vbox,argv) + + station = parseargs(argv[1:]) + offset_freq = 30e3 + IF_freq = offset_freq - station + + adc_rate = 64e6 + usrp_decim = 250 + if_rate = adc_rate / usrp_decim # 256 kHz + if_decim = 4 + demod_rate = if_rate / if_decim # 64 kHz + audio_decimation = 2 + audio_rate = demod_rate / audio_decimation # 16 kHz + + # usrp is data source + src = usrp.source_c (0, usrp_decim) + src.set_rx_freq (0, IF_freq) + actual_IF_freq =src.rx_freq(0) + actual_offset = actual_IF_freq + station + + #print actual_IF_freq + #print actual_offset + + src.set_pga(0,20) + # sound card as final sink + audio_sink = audio.sink (int (audio_rate)) + + channel_coeffs = \ + gr.firdes.low_pass (1.0, # gain + if_rate, # sampling rate + 9e3, # low pass cutoff freq + 10e3, # width of trans. band + gr.firdes.WIN_HANN) + + ddc = gr.freq_xlating_fir_filter_ccf (if_decim,channel_coeffs,-actual_offset,if_rate) + + magblock = gr.complex_to_mag() + volumecontrol = gr.multiply_const_ff(.003) + + # Deemphasis. Is this necessary on AM? + TAU = 75e-6 # 75us in US, 50us in EUR + fftaps = [ 1 - math.exp(-1/TAU/if_rate), 0] + fbtaps= [ 0 , math.exp(-1/TAU/if_rate) ] + + deemph = gr.iir_filter_ffd(fftaps,fbtaps) + + # compute FIR filter taps for audio filter + width_of_transition_band = audio_rate / 8 + audio_coeffs = gr.firdes.low_pass (1.0, # gain + if_rate, # sampling rate + 9e3, #audio_rate/2 - width_of_transition_band, + 4e3, # width_of_transition_band, + gr.firdes.WIN_HANN) + + # input: float; output: float + audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs) + + + + + print len(channel_coeffs) + print len(audio_coeffs) + + # now wire it all together + self.connect (src, ddc) + self.connect (ddc, magblock) + self.connect (magblock, volumecontrol) + self.connect (volumecontrol,deemph) + self.connect (deemph,audio_filter) + self.connect (audio_filter, (audio_sink, 0)) + + if 1: + pre_demod = fftsink.fft_sink_c (self, panel, title="Pre-Demodulation", fft_size=128, sample_rate=if_rate) + self.connect (src, pre_demod) + vbox.Add (pre_demod.win, 1, wx.EXPAND) + + if 0: + post_demod = fftsink.fft_sink_c (self, panel, title="Post Demodulation", fft_size=256, sample_rate=demod_rate) + self.connect (ddc, post_demod) + vbox.Add (post_demod.win, 1, wx.EXPAND) + + if 0: + post_filt = fftsink.fft_sink_f (self, panel, title="Post Filter", fft_size=512, sample_rate=audio_rate) + self.connect (magblock,post_filt) + vbox.Add (post_filt.win, 1, wx.EXPAND) + +def parseargs (args): + nargs = len (args) + if nargs == 1: + freq1 = float (args[0]) * 1e3 + else: + sys.stderr.write ('usage: am_rcv freq1\n') + sys.exit (1) + + return freq1 + +if __name__ == '__main__': + app = stdgui.stdapp (am_rx_graph, "AM RX") + app.MainLoop () + diff --git a/gnuradio-examples/python/usrp/limbo/ayfabtu.dat b/gnuradio-examples/python/usrp/limbo/ayfabtu.dat new file mode 100644 index 0000000000..5c65cf4833 Binary files /dev/null and b/gnuradio-examples/python/usrp/limbo/ayfabtu.dat differ diff --git a/gnuradio-examples/python/usrp/limbo/ayfabtu.py b/gnuradio-examples/python/usrp/limbo/ayfabtu.py new file mode 100755 index 0000000000..de6c26f58a --- /dev/null +++ b/gnuradio-examples/python/usrp/limbo/ayfabtu.py @@ -0,0 +1,169 @@ +#!/usr/bin/env python +# +# Copyright 2005 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio 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, or (at your option) +# any later version. +# +# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +# +# All Your Frequencies are Belong to Us! +# +# Transmit NBFM message on 25 channels simultaneously! +# + +from gnuradio import gr, gru, eng_notation +from gnuradio import usrp +from gnuradio import audio +from gnuradio import blks +from gnuradio import optfir +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import math +import sys +import random + +from gnuradio.wxgui import stdgui, fftsink +import wx + + +def make_random_complex_tuple(L): + result = [] + for x in range(L): + result.append(complex(random.gauss(0, 1),random.gauss(0, 1))) + + return tuple(result) + +def random_noise_c(): + src = gr.vector_source_c(make_random_complex_tuple(32*1024), True) + return src + + +def plot_taps(taps, sample_rate=2): + return gru.gnuplot_freqz (gru.freqz (taps, 1), sample_rate) + + +class ayfabtu_graph (stdgui.gui_flow_graph): + def __init__(self, frame, panel, vbox, argv): + stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv) + + parser = OptionParser (option_class=eng_option) + parser.add_option ("-c", "--duc-freq", type="eng_float", default=29.325e6, + help="set Tx ddc frequency to FREQ", metavar="FREQ") + (options, args) = parser.parse_args () + + nchan = 25 + IF_GAIN = 80000 + AUDIO_GAIN = 100 + + self.dac_rate = 128e6 + self.usrp_interp = 256 + self.usrp_rate = self.dac_rate / self.usrp_interp # 500 kS/s + self.audio_rate = 32000 # 32 kS/s + + self.audio_src = gr.file_source(gr.sizeof_float, "ayfabtu.dat", True) + + ahp_taps = gr.firdes.high_pass(1, # gain + 32e3, # Fs + 300, # cutoff + 600, # trans width + gr.firdes.WIN_HANN) + self.audio_hp = gr.fir_filter_fff(1, ahp_taps) + + self.audio_gain = gr.multiply_const_ff(AUDIO_GAIN) + + null_src = gr.null_source(gr.sizeof_gr_complex) + #noise_src = gr.noise_source_c(gr.GR_UNIFORM, 1, 0) + noise_src = random_noise_c() + + if 0: + artaps = optfir.low_pass(1, # gain + 2, # Fs + .75/32, # freq1 + 1.0/32, # freq2 + 1, # pb ripple in dB + 50, # stopband atten in dB + 2) # + extra taps + else: + artaps = gr.firdes.low_pass(1, # gain + 32e3*15,# Fs + 2.7e3, # cutoff + .3e3, # trans width + gr.firdes.WIN_HANN) + print "len(artaps) =", len(artaps) + self.audio_resampler = blks.rational_resampler_fff(self, 15, 32, artaps) + + self.fm_mod = blks.nbfm_tx(self, 15000, 15000, max_dev=4.5e3) + + + fbtaps = gr.firdes.low_pass(1, # gain + 25*15e3, # rate + 13e3, # cutoff + 2e3, # trans width + gr.firdes.WIN_HANN) + print "len(fbtabs) =", len(fbtaps) + #self.plot = plot_taps(fbtaps, 25*15e3) + self.filter_bank = blks.synthesis_filterbank(self, nchan, fbtaps) + + self.if_gain = gr.multiply_const_cc(IF_GAIN) + + if 0: + ifrtaps = optfir.low_pass(1, + 2, # Fs + .75/3, # freq1 + 1.0/3, # freq2 + 1, # pb ripple in dB + 50, # stopband atten in dB + 2) # + extra taps + else: + ifrtaps = gr.firdes.low_pass(1, + 2, # Fs + .75/3, # freq1 + .25/3, # trans width + gr.firdes.WIN_HANN) + + + print "len(ifrtaps) =", len(ifrtaps) + self.if_resampler = blks.rational_resampler_ccf(self, 4, 3, ifrtaps) + + + self.u = usrp.sink_c(0, 256) + self.u.set_tx_freq(0, options.duc_freq) + self.u.set_pga(0, self.u.pga_max()) + + # wire it all together + + self.connect(self.audio_src, self.audio_hp, self.audio_gain, + self.audio_resampler, self.fm_mod) + + null_sink = gr.null_sink(gr.sizeof_gr_complex) + + for i in range(nchan): + if True or i == 0: + self.connect(self.fm_mod, (self.filter_bank, i)) + else: + self.connect(null_src, (self.filter_bank, i)) + + self.connect(self.filter_bank, self.if_gain, self.if_resampler, self.u) + + +def main (): + app = stdgui.stdapp (ayfabtu_graph, "All Your Frequency Are Belong to Us") + app.MainLoop () + +if __name__ == '__main__': + main () diff --git a/gnuradio-examples/python/usrp/limbo/flexrf_debug.py b/gnuradio-examples/python/usrp/limbo/flexrf_debug.py new file mode 100755 index 0000000000..13d1db110d --- /dev/null +++ b/gnuradio-examples/python/usrp/limbo/flexrf_debug.py @@ -0,0 +1,169 @@ +#!/usr/bin/env python +# +# Copyright 2004 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio 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, or (at your option) +# any later version. +# +# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gru +from gnuradio import usrp +from gnuradio import eng_notation +from gnuradio.eng_option import eng_option +from gnuradio.wxgui import stdgui, fftsink, scopesink, slider +from optparse import OptionParser +import wx + +class app_flow_graph (stdgui.gui_flow_graph): + def __init__(self, frame, panel, vbox, argv): + stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv) + + self.frame = frame + self.panel = panel + + parser = OptionParser (option_class=eng_option) + parser.add_option ("-d", "--decim", type="int", default=8, + help="set fgpa decimation rate to DECIM") + parser.add_option ("-c", "--ddc-freq", type="eng_float", default=0, + help="set Digital downconverter frequency to FREQ", metavar="FREQ") + parser.add_option ("-f", "--freq", type="eng_float", default=950e6, + help="set RF downconverter frequency to FREQ", metavar="FREQ") + parser.add_option ("-m", "--mux", type="intx", default=0x32103210, + help="set fpga FR_RX_MUX register to MUX") + parser.add_option ("-g", "--gain", type="eng_float", default=0, + help="set Rx PGA gain in dB (default 0 dB)") + (options, args) = parser.parse_args () + + self.u = usrp.source_c (0, options.decim, 1, gru.hexint(options.mux), 0) + + self.u.set_verbose (0) + + input_rate = self.u.adc_freq () / self.u.decim_rate () + + block = fftsink.fft_sink_c (self, panel, fft_size=1024, sample_rate=input_rate) + self.connect (self.u, block) + vbox.Add (block.win, 10, wx.EXPAND) + + if 0: + c2f_1 = gr.complex_to_float () + scope = scopesink.scope_sink_f (self, panel, "Rx Data", input_rate) + vbox.Add (scope.win, 6, wx.EXPAND) + + self.connect (self.u,c2f_1) + self.connect ((c2f_1, 0), (scope, 0)) + self.connect ((c2f_1, 1), (scope, 1)) + + if 0: + rms_complex = gr.rms_cf(.0001) + rms_i = gr.rms_ff(.0001) + rms_q = gr.rms_ff(.0001) + + self.connect(self.u,rms_complex) + self.connect((c2f_1,0),rms_i) + self.connect((c2f_1,1),rms_q) + + ns1 = gr.null_sink(4) + ns2 = gr.null_sink(4) + ns3 = gr.null_sink(4) + + self.connect(rms_complex,ns1) + self.connect(rms_i,ns2) + self.connect(rms_q,ns3) + + # sliders + + #vbox.Add(slider.slider(panel, 0, 104, self.set_gain), 1, wx.ALIGN_CENTER) + + #vbox.Add(slider.slider(panel, 0, 4095, self.set_gain_gc1), 1, wx.ALIGN_CENTER) + #vbox.Add(slider.slider(panel, 0, 31, self.set_gain_gc2), 1, wx.ALIGN_CENTER) + #vbox.Add(slider.slider(panel, 0, 1, self.set_gain_dl), 1, wx.ALIGN_CENTER) + #vbox.Add(slider.slider(panel, 0, 200, self.set_gain_i), 1, wx.ALIGN_CENTER) + #vbox.Add(slider.slider(panel, 0, 200, self.set_gain_q), 1, wx.ALIGN_CENTER) + + self.offset = 0 + #vbox.Add(slider.slider(panel, -200, 200, self.set_offset_i), 1, wx.ALIGN_CENTER) + #vbox.Add(slider.slider(panel, -200, 200, self.set_offset_q), 1, wx.ALIGN_CENTER) + + vbox.Add(slider.slider(panel, 380, 480, self.set_rf_freq), 1, wx.EXPAND|wx.ALIGN_CENTER) + vbox.Add(slider.slider(panel, -32000, +32000, self.set_if_freq), 1, wx.EXPAND|wx.ALIGN_CENTER) + vbox.Add(slider.slider(panel, 0, 4095, self.set_gain), 1, wx.EXPAND|wx.ALIGN_CENTER) + + # build small control area at bottom + hbox = wx.BoxSizer (wx.HORIZONTAL) + hbox.Add ((1, 1), 1, wx.EXPAND) + hbox.Add (wx.StaticText (panel, -1, "Set ddc freq: "), 0, wx.ALIGN_CENTER) + self.tc_freq = wx.TextCtrl (panel, -1, "", style=wx.TE_PROCESS_ENTER) + hbox.Add (self.tc_freq, 0, wx.ALIGN_CENTER) + wx.EVT_TEXT_ENTER (self.tc_freq, self.tc_freq.GetId(), self.handle_text_enter) + hbox.Add ((1, 1), 1, wx.EXPAND) + # add it to the main vbox + vbox.Add (hbox, 0, wx.EXPAND) + + self.update_status_bar () + + def set_rf_freq (self,freq): + (success,actual_freq) = self.set_freq(1e6*freq) + if not success: + print "Failed on ",freq + def set_if_freq (self,freq): + self.u.set_rx_freq(0,freq*1e3) + + def set_gain (self,gain): + self.rfrx.set_gain(gain) + + def set_gain_i (self,gain): + self.u.set_pga(0,gain/10.0) + def set_gain_q (self,gain): + self.u.set_pga(1,gain/10.0) + + def set_offset_i(self,offset): + self.offset = (self.offset & 0x0000ffff) | ((offset&0xffff)<<16) + self.u._write_fpga_reg (3,self.offset) + + def set_offset_q(self,offset): + self.offset = (self.offset & 0xffff0000) | (offset&0xffff) + self.u._write_fpga_reg (3,self.offset) + + def handle_text_enter (self, event): + str = event.GetString () + self.tc_freq.Clear () + self.u.set_rx_freq (0, eng_notation.str_to_num (str)) + self.update_status_bar () + + def update_status_bar (self): + ddc_freq = self.u.rx_freq (0) + decim_rate = self.u.decim_rate () + sample_rate = self.u.adc_freq () / decim_rate + msg = "decim: %d %sS/s DDC: %s" % ( + decim_rate, + eng_notation.num_to_str (sample_rate), + eng_notation.num_to_str (ddc_freq)) + + self.frame.GetStatusBar().SetStatusText (msg, 1) + + def set_gain(self,gain): + assert gain>=0 and gain<4096 + self.u.write_aux_dac(0,0,int(gain)) + +def main (): + app = stdgui.stdapp (app_flow_graph, "USRP FFT") + app.MainLoop () + +if __name__ == '__main__': + main () + + diff --git a/gnuradio-examples/python/usrp/limbo/flexrf_siggen.py b/gnuradio-examples/python/usrp/limbo/flexrf_siggen.py new file mode 100755 index 0000000000..6a59148b88 --- /dev/null +++ b/gnuradio-examples/python/usrp/limbo/flexrf_siggen.py @@ -0,0 +1,148 @@ +#!/usr/bin/env python + +from gnuradio import gr, gru +from gnuradio import usrp +from gnuradio.eng_option import eng_option +from optparse import OptionParser +from gnuradio.wxgui import stdgui, slider +import wx + +class flex_siggen (stdgui.gui_flow_graph): + __slots__ = ['interp', 'waveform_type', 'waveform_ampl', + 'waveform_freq', 'waveform_offset', 'fg', 'usrp', + 'siggen', 'noisegen', 'src', 'file_sink' ] + + def __init__ (self,frame,panel,vbox,argv): + stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv) + + self.frame = frame + self.panel = panel + + parser = OptionParser (option_class=eng_option) + parser.add_option ("-a", "--amplitude", type="int", default=32000, + help="amplitude") + parser.add_option ("-i", "--interp", type="int", default=64, + help="set fpga interpolation rate to INTERP") + parser.add_option ("-n", "--nchannels", type="int", default=1, + help="set number of output channels to NCHANNELS") + (options, args) = parser.parse_args () + + self.waveform_type = gr.GR_CONST_WAVE + self.waveform_ampl = options.amplitude + self.waveform_freq = 100.12345e3 + self.waveform_offset = 0 + + self.interp = options.interp + self._instantiate_blocks () + self.usrp.set_nchannels (options.nchannels) + + self.dboard=self.usrp.db[0][0] + + self.set_waveform_type (self.waveform_type) + vbox.Add(slider.slider(panel, 390, 510, self.set_rf_freq), 1, wx.EXPAND|wx.ALIGN_CENTER) + vbox.Add(slider.slider(panel, -45000, +45000, self.set_if_freq), 1, wx.EXPAND|wx.ALIGN_CENTER) + #vbox.Add(slider.slider(panel, 0, 4095, self.set_gain), 1, wx.EXPAND|wx.ALIGN_CENTER) + + def usb_freq (self): + return self.usrp.dac_freq() / self.interp + + def usb_throughput (self): + return self.usb_freq () * 4 + + def set_waveform_type (self, type): + ''' + valid waveform types are: gr.GR_SIN_WAVE, gr.GR_CONST_WAVE, + gr.GR_UNIFORM and gr.GR_GAUSSIAN + ''' + self._configure_graph (type) + self.waveform_type = type + + def set_waveform_ampl (self, ampl): + self.waveform_ampl = ampl + self.siggen.set_amplitude (ampl) + self.noisegen.set_amplitude (ampl) + + def set_waveform_freq (self, freq): + self.waveform_freq = freq + self.siggen.set_frequency (freq) + + def set_if_freq (self, freq): + self.if_freq = freq + self.usrp.set_tx_freq (0,freq*1e3) + + def set_rf_freq (self, freq): + self.rf_freq = freq + (success,actual_freq) = self.dboard.set_freq (freq*1e6) + if not success: + print "Failed on ", freq + + def set_waveform_offset (self, offset): + self.waveform_offset = offset + self.siggen.set_offset (offset) + + def set_interpolator (self, interp): + self.interp = interp + self.siggen.set_sampling_freq (self.usb_freq ()) + self.usrp.set_interp_rate (interp) + + def set_duc_freq (self, freq): + self.usrp.set_tx_freq (0, freq) + + def _instantiate_blocks (self): + self.src = None + self.usrp = usrp.sink_c (0, self.interp) + + self.siggen = gr.sig_source_c (self.usb_freq (), + gr.GR_SIN_WAVE, + self.waveform_freq, + self.waveform_ampl, + self.waveform_offset) + + self.noisegen = gr.noise_source_c (gr.GR_UNIFORM, + self.waveform_ampl) + print "done" + + def _configure_graph (self, type): + was_running = self.is_running () + if was_running: + self.stop () + self.disconnect_all () + if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE: + self.connect (self.siggen, self.usrp) + self.siggen.set_waveform (type) + self.src = self.siggen + elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN: + self.connect (self.noisegen, self.usrp) + self.noisegen.set_type (type) + self.src = self.noisegen + else: + raise ValueError, type + if was_running: + self.start () + + +if __name__ == '__main__': + parser = OptionParser (option_class=eng_option) + parser.add_option ("--sine", dest="type", action="store_const", const=gr.GR_SIN_WAVE, + help="generate a complex sinusoid [default]", default=gr.GR_SIN_WAVE) + parser.add_option ("--const", dest="type", action="store_const", const=gr.GR_CONST_WAVE, + help="generate a constant output") + parser.add_option ("--gaussian", dest="type", action="store_const", const=gr.GR_GAUSSIAN, + help="generate Gaussian random output") + parser.add_option ("--uniform", dest="type", action="store_const", const=gr.GR_UNIFORM, + help="generate Uniform random output") + parser.add_option ("-f", "--freq", type="eng_float", default=100e3, + help="set waveform frequency to FREQ") + parser.add_option ("-r", "--rf-freq", type="eng_float", default=910e6, + help="set waveform frequency to FREQ") + parser.add_option ("-a", "--amplitude", type="eng_float", default=16e3, + help="set waveform amplitude to AMPLITUDE", metavar="AMPL") + parser.add_option ("-o", "--offset", type="eng_float", default=0, + help="set waveform offset to OFFSET") + parser.add_option ("-c", "--duc-freq", type="eng_float", default=0, + help="set Tx DUC frequency to FREQ", metavar="FREQ") + parser.add_option ("-m", "--mux", type="intx", default=0x98, + help="set output mux register") + + app = stdgui.stdapp (flex_siggen, "USRP FlexRF Siggen") + app.MainLoop () diff --git a/gnuradio-examples/python/usrp/limbo/siggen_min2.py b/gnuradio-examples/python/usrp/limbo/siggen_min2.py new file mode 100755 index 0000000000..8709e3373f --- /dev/null +++ b/gnuradio-examples/python/usrp/limbo/siggen_min2.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python + +from gnuradio import gr +from gnuradio import usrp +from gnuradio import eng_notation +from gnuradio.eng_option import eng_option +from optparse import OptionParser + + + +def build_graph (): + + # interp = 32 + interp = 64 + nchan = 2 + + if nchan == 1: + mux = 0x0098 + #mux = 0x9800 + else: + mux = 0xba98 + + f0 = 100e3 + a0 = 16e3 + duc0 = 5e6 + + f1 = 50e3 + a1 = 16e3 + duc1 = 7e6 + + fg = gr.flow_graph () + + u = usrp.sink_c (0, interp, nchan, mux) + sample_rate = u.dac_freq () / interp + print "sample_rate = ", eng_notation.num_to_str (sample_rate) + print "usb_sample_rate = ", eng_notation.num_to_str (sample_rate * nchan) + + u.set_tx_freq (0, duc0) + u.set_tx_freq (1, duc1) + + interleave = gr.interleave (gr.sizeof_gr_complex) + fg.connect (interleave, u) + + src0 = gr.sig_source_c (sample_rate, gr.GR_SIN_WAVE, f0, a0, 0) + fg.connect (src0, (interleave, 0)) + + if nchan == 2: + if 1: + src1 = gr.sig_source_c (sample_rate, gr.GR_SIN_WAVE, f1, a1, 0) + else: + src1 = gr.noise_source_c (gr.GR_UNIFORM, a1) + fg.connect (src1, (interleave, 1)) + + return fg + + +if __name__ == '__main__': + fg = build_graph () + fg.start () + raw_input ('Press Enter to quit: ') + fg.stop () + diff --git a/gnuradio-examples/python/usrp/limbo/test_dft_analysis.py b/gnuradio-examples/python/usrp/limbo/test_dft_analysis.py new file mode 100755 index 0000000000..a1d9eda46c --- /dev/null +++ b/gnuradio-examples/python/usrp/limbo/test_dft_analysis.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +from gnuradio import gr, gru, blks +from gnuradio.wxgui import stdgui, fftsink, slider +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import wx + +class test_graph (stdgui.gui_flow_graph): + def __init__(self, frame, panel, vbox, argv): + stdgui.gui_flow_graph.__init__(self, frame, panel, vbox, argv) + + parser = OptionParser (option_class=eng_option) + (options, args) = parser.parse_args () + + sample_rate = 16e3 + mpoints = 4 + ampl = 1000 + freq = 0 + + lo_freq = 1e6 + lo_ampl = 1 + + vbox.Add(slider.slider(panel, + -sample_rate/2, sample_rate/2, + self.set_lo_freq), 0, wx.ALIGN_CENTER) + + + src = gr.sig_source_c(sample_rate, gr.GR_CONST_WAVE, + freq, ampl, 0) + + self.lo = gr.sig_source_c(sample_rate, gr.GR_SIN_WAVE, + lo_freq, lo_ampl, 0) + + mixer = gr.multiply_cc() + self.connect(src, (mixer, 0)) + self.connect(self.lo, (mixer, 1)) + + # We add these throttle blocks so that this demo doesn't + # suck down all the CPU available. Normally you wouldn't use these. + thr = gr.throttle(gr.sizeof_gr_complex, sample_rate) + + taps = gr.firdes.low_pass(1, # gain + 1, # rate + 1.0/mpoints * 0.4, # cutoff + 1.0/mpoints * 0.1, # trans width + gr.firdes.WIN_HANN) + print len(taps) + analysis = blks.analysis_filterbank(self, mpoints, taps) + + self.connect(mixer, thr) + self.connect(thr, analysis) + + for i in range(mpoints): + fft = fftsink.fft_sink_c(self, frame, fft_size=128, + sample_rate=sample_rate/mpoints, + fft_rate=5, + title="Ch %d" % (i,)) + self.connect((analysis, i), fft) + vbox.Add(fft.win, 1, wx.EXPAND) + + def set_lo_freq(self, freq): + self.lo.set_frequency(freq) + + + +def main (): + app = stdgui.stdapp (test_graph, "Test DFT filterbank") + app.MainLoop () + +if __name__ == '__main__': + main () diff --git a/gnuradio-examples/python/usrp/limbo/test_dft_synth.py b/gnuradio-examples/python/usrp/limbo/test_dft_synth.py new file mode 100755 index 0000000000..60a49e3b37 --- /dev/null +++ b/gnuradio-examples/python/usrp/limbo/test_dft_synth.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python + +from gnuradio import gr, gru, blks +from gnuradio.wxgui import stdgui, fftsink +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import wx +import random + + +def make_random_complex_tuple(L, gain=1): + result = [] + for x in range(L): + result.append(gain * complex(random.gauss(0, 1),random.gauss(0, 1))) + + return tuple(result) + +def random_noise_c(gain=1): + src = gr.vector_source_c(make_random_complex_tuple(32*1024, gain), True) + return src + + +class test_graph (stdgui.gui_flow_graph): + def __init__(self, frame, panel, vbox, argv): + stdgui.gui_flow_graph.__init__(self, frame, panel, vbox, argv) + + parser = OptionParser (option_class=eng_option) + (options, args) = parser.parse_args () + + sample_rate = 16e6 + mpoints = 16 + ampl = 1000 + + enable = mpoints * [0] + enable[0] = 1 + + taps = gr.firdes.low_pass(1, # gain + 1, # rate + 1.0/mpoints * 0.4, # cutoff + 1.0/mpoints * 0.1, # trans width + gr.firdes.WIN_HANN) + + synth = blks.synthesis_filterbank(self, mpoints, taps) + + null_source = gr.null_source(gr.sizeof_gr_complex) + + if 0: + for i in range(mpoints): + s = gr.sig_source_c(sample_rate/mpoints, gr.GR_SIN_WAVE, + 300e3, ampl * enable[i], 0) + self.connect(s, (synth, i)) + + else: + for i in range(mpoints): + if i == 0: + s = gr.sig_source_c(sample_rate/mpoints, gr.GR_SIN_WAVE, + 300e3, ampl * enable[i], 0) + #s = random_noise_c(ampl) + self.connect(s, (synth, i)) + else: + self.connect(null_source, (synth, i)) + + + # We add these throttle blocks so that this demo doesn't + # suck down all the CPU available. Normally you wouldn't use these. + thr = gr.throttle(gr.sizeof_gr_complex, sample_rate) + fft = fftsink.fft_sink_c(self, frame, fft_size=1024, + sample_rate=sample_rate) + vbox.Add(fft.win, 1, wx.EXPAND) + + self.connect(synth, thr, fft) + + +def main (): + app = stdgui.stdapp (test_graph, "Test DFT filterbank") + app.MainLoop () + +if __name__ == '__main__': + main () diff --git a/gnuradio-examples/python/usrp/limbo/tvrx_am_rcv_gui.py b/gnuradio-examples/python/usrp/limbo/tvrx_am_rcv_gui.py new file mode 100755 index 0000000000..403cf3fa4d --- /dev/null +++ b/gnuradio-examples/python/usrp/limbo/tvrx_am_rcv_gui.py @@ -0,0 +1,154 @@ +#!/usr/bin/env python +# +# Copyright 2004 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio 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, or (at your option) +# any later version. +# +# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# +# +# Demodulate an AM signal from the TVRX or a recorded file. +# The file format must be 256 ksps, complex data. +# + +from gnuradio import gr, gru, eng_notation +from gnuradio import audio_oss as audio +from gnuradio import usrp +from gnuradio import tv_rx +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import sys +import math +from gnuradio.wxgui import stdgui, fftsink, scopesink +import wx + +# +# return a gr.flow_graph +# +class wfm_rx_graph (stdgui.gui_flow_graph): + def __init__(self,frame,panel,vbox,argv): + stdgui.gui_flow_graph.__init__ (self,frame,panel,vbox,argv) + + #set rf freq + rf_freq = 120.e6 + + # Decimation rate from USRP ADC to IF. + usrp_decim = 100 + + # Calculate the sampling rate of the USRP and capture file. + # Decimate the IF sampling rate down by 4 to 64 ksps + # This is a flow graph that has an input (capture file) and output (audio channel). + #self = gr.flow_graph () + + # Signal source is assumed to be 256 kspb / complex data stream. + which_side = 0 + # usrp is data source + if which_side == 0: + src = usrp.source_c (0, usrp_decim, 1, gru.hexint(0xf0f0f0f0), 0) + else: + src = usrp.source_c (0, usrp_decim, 1, gru.hexint(0xf0f0f0f2), 0) + + if_rate = 640e3 # src.adc_freq() / usrp_decim + if_decim = 5 + demod_rate = if_rate / if_decim + + audio_decimation = 4 + audio_rate = demod_rate / audio_decimation + + # set up frontend + dboard = tv_rx.tv_rx (src, which_side) + self.dboard = dboard + (success, actual_freq) = dboard.set_freq(rf_freq) + assert success + + if_freq = rf_freq - actual_freq + src.set_rx_freq (0, -if_freq) + + print "actual freq ", actual_freq + print "IF freq ", if_freq + + dboard.set_gain(50) + + #src = gr.file_source (gr.sizeof_gr_complex, "samples/atis_ffz_am_baseband_256k_complex.dat") + #src = gr.file_source (gr.sizeof_gr_complex, "samples/garagedoor1.dat", True) + + #channel_coeffs = gr.firdes.band_pass ( + # 1.0, # gain + # if_rate, + # 10, # center of low transition band + # 10000, # center of hi transition band + # 200, # width of transition band + # gr.firdes.WIN_HAMMING) + + channel_coeffs = gr.firdes.low_pass (1.0, if_rate, 10e3, 4e3, gr.firdes.WIN_HANN) + print "len(channel_coeffs) = ", len(channel_coeffs) + + # Tune to the desired frequency. + ddc = gr.freq_xlating_fir_filter_ccf (if_decim, channel_coeffs, -20e3, if_rate) + + # Demodule with classic sqrt (I*I + Q*Q) + magblock = gr.complex_to_mag() + + # Scale the audio + volumecontrol = gr.multiply_const_ff(.1) + + #band-pass + audio_coeffs = gr.firdes.band_pass ( + 1.0, # gain + demod_rate, + 10, # center of low transition band + 6000, # center of hi transition band + 200, # width of transition band + gr.firdes.WIN_HAMMING) + + + # Low pass filter the demodulator output + #audio_coeffs = gr.firdes.low_pass (1.0, demod_rate, 500, 200, gr.firdes.WIN_HANN) + print "len(audio_coeffs) = ", len(audio_coeffs) + + # input: float; output: float + audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs) + + # sound card as final sink + audio_sink = audio.sink (int (audio_rate)) + + # now wire it all together + self.connect (src, ddc) + self.connect (ddc, magblock) + self.connect (magblock, volumecontrol) + self.connect (volumecontrol, audio_filter) + self.connect (audio_filter, (audio_sink, 0)) + + d_win = fftsink.fft_sink_c (self, panel, title="RF", fft_size=512, sample_rate=if_rate) + self.connect (src,d_win) + vbox.Add (d_win.win, 4, wx.EXPAND) + + p_win = fftsink.fft_sink_c (self, panel, title="IF", fft_size=512, sample_rate=demod_rate) + self.connect (ddc,p_win) + vbox.Add (p_win.win, 4, wx.EXPAND) + + r_win = fftsink.fft_sink_f (self, panel, title="Audio", fft_size=512, sample_rate=audio_rate) + self.connect (audio_filter,r_win) + vbox.Add (r_win.win, 4, wx.EXPAND) + + #audio_oscope = scopesink.scope_sink_f (self, panel, "Oscope Data", audio_rate) + #self.connect (audio_filter, audio_oscope) + #vbox.Add (audio_oscope.win, 4, wx.EXPAND) + +if __name__ == '__main__': + + app = stdgui.stdapp (wfm_rx_graph, "TVRX AM RX") + app.MainLoop () diff --git a/gnuradio-examples/python/usrp/limbo/usrp_fft_old.py b/gnuradio-examples/python/usrp/limbo/usrp_fft_old.py new file mode 100755 index 0000000000..5edb372b98 --- /dev/null +++ b/gnuradio-examples/python/usrp/limbo/usrp_fft_old.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python +# +# Copyright 2004 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio 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, or (at your option) +# any later version. +# +# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gru +from gnuradio import usrp +from gnuradio import eng_notation +from gnuradio.eng_option import eng_option +from gnuradio.wxgui import stdgui, fftsink, scopesink +from optparse import OptionParser +import wx + +class app_flow_graph (stdgui.gui_flow_graph): + def __init__(self, frame, panel, vbox, argv): + stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv) + + self.frame = frame + self.panel = panel + + parser = OptionParser (option_class=eng_option) + parser.add_option ("-d", "--decim", type="int", default=16, + help="set fgpa decimation rate to DECIM") + parser.add_option ("-c", "--ddc-freq", type="eng_float", default=0, + help="set Rx DDC frequency to FREQ", metavar="FREQ") + parser.add_option ("-m", "--mux", type="intx", default=0x32103210, + help="set fpga FR_RX_MUX register to MUX") + parser.add_option ("-g", "--gain", type="eng_float", default=0, + help="set Rx PGA gain in dB (default 0 dB)") + (options, args) = parser.parse_args () + + self.u = usrp.source_c (0, options.decim, 1, gru.hexint(options.mux), 0) + self.u.set_rx_freq (0, options.ddc_freq) + + self.u.set_pga (0, options.gain) + self.u.set_pga (1, options.gain) + + self.u.set_verbose (0) + + input_rate = self.u.adc_freq () / self.u.decim_rate () + + fft = fftsink.fft_sink_c (self, panel, fft_size=1024, sample_rate=input_rate) + #fft = fftsink.fft_sink_c (self, panel, fft_size=1024, fft_rate=50, sample_rate=input_rate) + self.connect (self.u, fft) + vbox.Add (fft.win, 10, wx.EXPAND) + + if 0: + c2f_1 = gr.complex_to_float () + scope = scopesink.scope_sink_f (self, panel, "Rx Data", input_rate) + vbox.Add (scope.win, 4, wx.EXPAND) + + self.connect (self.u,c2f_1) + self.connect ((c2f_1, 0), (scope, 0)) + self.connect ((c2f_1, 1), (scope, 1)) + + # build small control area at bottom + hbox = wx.BoxSizer (wx.HORIZONTAL) + hbox.Add ((1, 1), 1, wx.EXPAND) + hbox.Add (wx.StaticText (panel, -1, "Set ddc freq: "), 0, wx.ALIGN_CENTER) + self.tc_freq = wx.TextCtrl (panel, -1, "", style=wx.TE_PROCESS_ENTER) + hbox.Add (self.tc_freq, 0, wx.ALIGN_CENTER) + wx.EVT_TEXT_ENTER (self.tc_freq, self.tc_freq.GetId(), self.handle_text_enter) + hbox.Add ((1, 1), 1, wx.EXPAND) + # add it to the main vbox + vbox.Add (hbox, 0, wx.EXPAND) + + self.update_status_bar () + + def handle_text_enter (self, event): + str = event.GetString () + self.tc_freq.Clear () + self.u.set_rx_freq (0, eng_notation.str_to_num (str)) + self.update_status_bar () + + def update_status_bar (self): + ddc_freq = self.u.rx_freq (0) + decim_rate = self.u.decim_rate () + sample_rate = self.u.adc_freq () / decim_rate + msg = "decim: %d %sS/s DDC: %s" % ( + decim_rate, + eng_notation.num_to_str (sample_rate), + eng_notation.num_to_str (ddc_freq)) + + self.frame.GetStatusBar().SetStatusText (msg, 1) + + + +def main (): + app = stdgui.stdapp (app_flow_graph, "USRP FFT") + app.MainLoop () + +if __name__ == '__main__': + main () diff --git a/gnuradio-examples/python/usrp/siggen_min2.py b/gnuradio-examples/python/usrp/siggen_min2.py deleted file mode 100755 index 8709e3373f..0000000000 --- a/gnuradio-examples/python/usrp/siggen_min2.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import usrp -from gnuradio import eng_notation -from gnuradio.eng_option import eng_option -from optparse import OptionParser - - - -def build_graph (): - - # interp = 32 - interp = 64 - nchan = 2 - - if nchan == 1: - mux = 0x0098 - #mux = 0x9800 - else: - mux = 0xba98 - - f0 = 100e3 - a0 = 16e3 - duc0 = 5e6 - - f1 = 50e3 - a1 = 16e3 - duc1 = 7e6 - - fg = gr.flow_graph () - - u = usrp.sink_c (0, interp, nchan, mux) - sample_rate = u.dac_freq () / interp - print "sample_rate = ", eng_notation.num_to_str (sample_rate) - print "usb_sample_rate = ", eng_notation.num_to_str (sample_rate * nchan) - - u.set_tx_freq (0, duc0) - u.set_tx_freq (1, duc1) - - interleave = gr.interleave (gr.sizeof_gr_complex) - fg.connect (interleave, u) - - src0 = gr.sig_source_c (sample_rate, gr.GR_SIN_WAVE, f0, a0, 0) - fg.connect (src0, (interleave, 0)) - - if nchan == 2: - if 1: - src1 = gr.sig_source_c (sample_rate, gr.GR_SIN_WAVE, f1, a1, 0) - else: - src1 = gr.noise_source_c (gr.GR_UNIFORM, a1) - fg.connect (src1, (interleave, 1)) - - return fg - - -if __name__ == '__main__': - fg = build_graph () - fg.start () - raw_input ('Press Enter to quit: ') - fg.stop () - diff --git a/gnuradio-examples/python/usrp/test_counting.py b/gnuradio-examples/python/usrp/test_counting.py deleted file mode 100755 index ccfa948c61..0000000000 --- a/gnuradio-examples/python/usrp/test_counting.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -""" -Check Rx path or USRP Rev 1. - -This configures the USRP to return a periodic sequence of integers -""" - -from gnuradio import gr -from gnuradio import usrp - -def build_graph (): - rx_decim = 32 - - fg = gr.flow_graph () - usrp_rx = usrp.source_s (0, rx_decim, 1, 0x32103210, usrp.FPGA_MODE_COUNTING) - sink = gr.check_counting_s () - fg.connect (usrp_rx, sink) - - # file_sink = gr.file_sink (gr.sizeof_short, 'counting.dat') - # fg.connect (usrp_rx, file_sink) - - return fg - -def main (): - fg = build_graph () - try: - fg.run() - except KeyboardInterrupt: - pass - -if __name__ == '__main__': - main () diff --git a/gnuradio-examples/python/usrp/test_dft_analysis.py b/gnuradio-examples/python/usrp/test_dft_analysis.py deleted file mode 100755 index a1d9eda46c..0000000000 --- a/gnuradio-examples/python/usrp/test_dft_analysis.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr, gru, blks -from gnuradio.wxgui import stdgui, fftsink, slider -from gnuradio.eng_option import eng_option -from optparse import OptionParser -import wx - -class test_graph (stdgui.gui_flow_graph): - def __init__(self, frame, panel, vbox, argv): - stdgui.gui_flow_graph.__init__(self, frame, panel, vbox, argv) - - parser = OptionParser (option_class=eng_option) - (options, args) = parser.parse_args () - - sample_rate = 16e3 - mpoints = 4 - ampl = 1000 - freq = 0 - - lo_freq = 1e6 - lo_ampl = 1 - - vbox.Add(slider.slider(panel, - -sample_rate/2, sample_rate/2, - self.set_lo_freq), 0, wx.ALIGN_CENTER) - - - src = gr.sig_source_c(sample_rate, gr.GR_CONST_WAVE, - freq, ampl, 0) - - self.lo = gr.sig_source_c(sample_rate, gr.GR_SIN_WAVE, - lo_freq, lo_ampl, 0) - - mixer = gr.multiply_cc() - self.connect(src, (mixer, 0)) - self.connect(self.lo, (mixer, 1)) - - # We add these throttle blocks so that this demo doesn't - # suck down all the CPU available. Normally you wouldn't use these. - thr = gr.throttle(gr.sizeof_gr_complex, sample_rate) - - taps = gr.firdes.low_pass(1, # gain - 1, # rate - 1.0/mpoints * 0.4, # cutoff - 1.0/mpoints * 0.1, # trans width - gr.firdes.WIN_HANN) - print len(taps) - analysis = blks.analysis_filterbank(self, mpoints, taps) - - self.connect(mixer, thr) - self.connect(thr, analysis) - - for i in range(mpoints): - fft = fftsink.fft_sink_c(self, frame, fft_size=128, - sample_rate=sample_rate/mpoints, - fft_rate=5, - title="Ch %d" % (i,)) - self.connect((analysis, i), fft) - vbox.Add(fft.win, 1, wx.EXPAND) - - def set_lo_freq(self, freq): - self.lo.set_frequency(freq) - - - -def main (): - app = stdgui.stdapp (test_graph, "Test DFT filterbank") - app.MainLoop () - -if __name__ == '__main__': - main () diff --git a/gnuradio-examples/python/usrp/test_dft_synth.py b/gnuradio-examples/python/usrp/test_dft_synth.py deleted file mode 100755 index 60a49e3b37..0000000000 --- a/gnuradio-examples/python/usrp/test_dft_synth.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr, gru, blks -from gnuradio.wxgui import stdgui, fftsink -from gnuradio.eng_option import eng_option -from optparse import OptionParser -import wx -import random - - -def make_random_complex_tuple(L, gain=1): - result = [] - for x in range(L): - result.append(gain * complex(random.gauss(0, 1),random.gauss(0, 1))) - - return tuple(result) - -def random_noise_c(gain=1): - src = gr.vector_source_c(make_random_complex_tuple(32*1024, gain), True) - return src - - -class test_graph (stdgui.gui_flow_graph): - def __init__(self, frame, panel, vbox, argv): - stdgui.gui_flow_graph.__init__(self, frame, panel, vbox, argv) - - parser = OptionParser (option_class=eng_option) - (options, args) = parser.parse_args () - - sample_rate = 16e6 - mpoints = 16 - ampl = 1000 - - enable = mpoints * [0] - enable[0] = 1 - - taps = gr.firdes.low_pass(1, # gain - 1, # rate - 1.0/mpoints * 0.4, # cutoff - 1.0/mpoints * 0.1, # trans width - gr.firdes.WIN_HANN) - - synth = blks.synthesis_filterbank(self, mpoints, taps) - - null_source = gr.null_source(gr.sizeof_gr_complex) - - if 0: - for i in range(mpoints): - s = gr.sig_source_c(sample_rate/mpoints, gr.GR_SIN_WAVE, - 300e3, ampl * enable[i], 0) - self.connect(s, (synth, i)) - - else: - for i in range(mpoints): - if i == 0: - s = gr.sig_source_c(sample_rate/mpoints, gr.GR_SIN_WAVE, - 300e3, ampl * enable[i], 0) - #s = random_noise_c(ampl) - self.connect(s, (synth, i)) - else: - self.connect(null_source, (synth, i)) - - - # We add these throttle blocks so that this demo doesn't - # suck down all the CPU available. Normally you wouldn't use these. - thr = gr.throttle(gr.sizeof_gr_complex, sample_rate) - fft = fftsink.fft_sink_c(self, frame, fft_size=1024, - sample_rate=sample_rate) - vbox.Add(fft.win, 1, wx.EXPAND) - - self.connect(synth, thr, fft) - - -def main (): - app = stdgui.stdapp (test_graph, "Test DFT filterbank") - app.MainLoop () - -if __name__ == '__main__': - main () diff --git a/gnuradio-examples/python/usrp/test_digital_loopback_counting.py b/gnuradio-examples/python/usrp/test_digital_loopback_counting.py deleted file mode 100755 index 51a705a057..0000000000 --- a/gnuradio-examples/python/usrp/test_digital_loopback_counting.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -""" -Digital loopback (Tx to Rx) for the USRP Rev1. -""" - - -from gnuradio import gr -from gnuradio import usrp - - -def ramp_source (fg): - period = 2**16 - src = gr.vector_source_s (range (-period/2, period/2, 1), True) - return src - -def build_graph (): - tx_interp = 32 # tx should be twice rx - rx_decim = 16 - - fg = gr.flow_graph () - - data_src = ramp_source (fg) - # usrp_tx = usrp.sink_s (0, tx_interp, 1, 0x98) - usrp_tx = usrp.sink_s (0, tx_interp) - fg.connect (data_src, usrp_tx) - - usrp_rx = usrp.source_s (0, rx_decim, 1, 0x32103210, usrp.FPGA_MODE_LOOPBACK) - sink = gr.check_counting_s () - fg.connect (usrp_rx, sink) - - # file_sink = gr.file_sink (gr.sizeof_short, "loopback.dat") - # fg.connect (usrp_rx, file_sink) - - return fg - -def main (): - fg = build_graph () - try: - fg.run() - except KeyboardInterrupt: - pass - -if __name__ == '__main__': - main () diff --git a/gnuradio-examples/python/usrp/test_digital_loopback_lfsr.py b/gnuradio-examples/python/usrp/test_digital_loopback_lfsr.py deleted file mode 100755 index 446ca30a16..0000000000 --- a/gnuradio-examples/python/usrp/test_digital_loopback_lfsr.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -""" -Digital loopback (Tx to Rx) for the USRP Rev1. -""" - -from gnuradio import gr -from gnuradio import usrp - - -def build_graph (): - tx_interp = 32 # tx should be twice rx - rx_decim = 16 - - fg = gr.flow_graph () - - data_src = gr.lfsr_32k_source_s () - - # usrp_tx = usrp.sink_s (0, tx_interp, 1, 0x98) - usrp_tx = usrp.sink_s (0, tx_interp) - - fg.connect (data_src, usrp_tx) - - usrp_rx = usrp.source_s (0, rx_decim, 1, 0x32103210, usrp.FPGA_MODE_LOOPBACK) - - sink = gr.check_lfsr_32k_s () - fg.connect (usrp_rx, sink) - - # file_sink = gr.file_sink (gr.sizeof_short, "loopback.dat") - # fg.connect (usrp_rx, file_sink) - - return fg - -def main (): - fg = build_graph () - try: - fg.run() - except KeyboardInterrupt: - pass - -if __name__ == '__main__': - main () diff --git a/gnuradio-examples/python/usrp/tvrx_am_rcv_gui.py b/gnuradio-examples/python/usrp/tvrx_am_rcv_gui.py deleted file mode 100755 index 403cf3fa4d..0000000000 --- a/gnuradio-examples/python/usrp/tvrx_am_rcv_gui.py +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# -# -# Demodulate an AM signal from the TVRX or a recorded file. -# The file format must be 256 ksps, complex data. -# - -from gnuradio import gr, gru, eng_notation -from gnuradio import audio_oss as audio -from gnuradio import usrp -from gnuradio import tv_rx -from gnuradio.eng_option import eng_option -from optparse import OptionParser -import sys -import math -from gnuradio.wxgui import stdgui, fftsink, scopesink -import wx - -# -# return a gr.flow_graph -# -class wfm_rx_graph (stdgui.gui_flow_graph): - def __init__(self,frame,panel,vbox,argv): - stdgui.gui_flow_graph.__init__ (self,frame,panel,vbox,argv) - - #set rf freq - rf_freq = 120.e6 - - # Decimation rate from USRP ADC to IF. - usrp_decim = 100 - - # Calculate the sampling rate of the USRP and capture file. - # Decimate the IF sampling rate down by 4 to 64 ksps - # This is a flow graph that has an input (capture file) and output (audio channel). - #self = gr.flow_graph () - - # Signal source is assumed to be 256 kspb / complex data stream. - which_side = 0 - # usrp is data source - if which_side == 0: - src = usrp.source_c (0, usrp_decim, 1, gru.hexint(0xf0f0f0f0), 0) - else: - src = usrp.source_c (0, usrp_decim, 1, gru.hexint(0xf0f0f0f2), 0) - - if_rate = 640e3 # src.adc_freq() / usrp_decim - if_decim = 5 - demod_rate = if_rate / if_decim - - audio_decimation = 4 - audio_rate = demod_rate / audio_decimation - - # set up frontend - dboard = tv_rx.tv_rx (src, which_side) - self.dboard = dboard - (success, actual_freq) = dboard.set_freq(rf_freq) - assert success - - if_freq = rf_freq - actual_freq - src.set_rx_freq (0, -if_freq) - - print "actual freq ", actual_freq - print "IF freq ", if_freq - - dboard.set_gain(50) - - #src = gr.file_source (gr.sizeof_gr_complex, "samples/atis_ffz_am_baseband_256k_complex.dat") - #src = gr.file_source (gr.sizeof_gr_complex, "samples/garagedoor1.dat", True) - - #channel_coeffs = gr.firdes.band_pass ( - # 1.0, # gain - # if_rate, - # 10, # center of low transition band - # 10000, # center of hi transition band - # 200, # width of transition band - # gr.firdes.WIN_HAMMING) - - channel_coeffs = gr.firdes.low_pass (1.0, if_rate, 10e3, 4e3, gr.firdes.WIN_HANN) - print "len(channel_coeffs) = ", len(channel_coeffs) - - # Tune to the desired frequency. - ddc = gr.freq_xlating_fir_filter_ccf (if_decim, channel_coeffs, -20e3, if_rate) - - # Demodule with classic sqrt (I*I + Q*Q) - magblock = gr.complex_to_mag() - - # Scale the audio - volumecontrol = gr.multiply_const_ff(.1) - - #band-pass - audio_coeffs = gr.firdes.band_pass ( - 1.0, # gain - demod_rate, - 10, # center of low transition band - 6000, # center of hi transition band - 200, # width of transition band - gr.firdes.WIN_HAMMING) - - - # Low pass filter the demodulator output - #audio_coeffs = gr.firdes.low_pass (1.0, demod_rate, 500, 200, gr.firdes.WIN_HANN) - print "len(audio_coeffs) = ", len(audio_coeffs) - - # input: float; output: float - audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs) - - # sound card as final sink - audio_sink = audio.sink (int (audio_rate)) - - # now wire it all together - self.connect (src, ddc) - self.connect (ddc, magblock) - self.connect (magblock, volumecontrol) - self.connect (volumecontrol, audio_filter) - self.connect (audio_filter, (audio_sink, 0)) - - d_win = fftsink.fft_sink_c (self, panel, title="RF", fft_size=512, sample_rate=if_rate) - self.connect (src,d_win) - vbox.Add (d_win.win, 4, wx.EXPAND) - - p_win = fftsink.fft_sink_c (self, panel, title="IF", fft_size=512, sample_rate=demod_rate) - self.connect (ddc,p_win) - vbox.Add (p_win.win, 4, wx.EXPAND) - - r_win = fftsink.fft_sink_f (self, panel, title="Audio", fft_size=512, sample_rate=audio_rate) - self.connect (audio_filter,r_win) - vbox.Add (r_win.win, 4, wx.EXPAND) - - #audio_oscope = scopesink.scope_sink_f (self, panel, "Oscope Data", audio_rate) - #self.connect (audio_filter, audio_oscope) - #vbox.Add (audio_oscope.win, 4, wx.EXPAND) - -if __name__ == '__main__': - - app = stdgui.stdapp (wfm_rx_graph, "TVRX AM RX") - app.MainLoop () diff --git a/gnuradio-examples/python/usrp/usrp_fft.py b/gnuradio-examples/python/usrp/usrp_fft.py deleted file mode 100755 index 353c89218f..0000000000 --- a/gnuradio-examples/python/usrp/usrp_fft.py +++ /dev/null @@ -1,254 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2005 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from gnuradio import gr, gru -from gnuradio import usrp -from gnuradio import eng_notation -from gnuradio.eng_option import eng_option -from gnuradio.wxgui import stdgui, fftsink, waterfallsink, scopesink, form, slider -from optparse import OptionParser -import wx -import sys - - -def pick_subdevice(u): - """ - The user didn't specify a subdevice on the command line. - If there's a daughterboard on A, select A. - If there's a daughterboard on B, select B. - Otherwise, select A. - """ - if u.db[0][0].dbid() >= 0: # dbid is < 0 if there's no d'board or a problem - return (0, 0) - if u.db[1][0].dbid() >= 0: - return (1, 0) - return (0, 0) - - -class app_flow_graph(stdgui.gui_flow_graph): - def __init__(self, frame, panel, vbox, argv): - stdgui.gui_flow_graph.__init__(self) - - self.frame = frame - self.panel = panel - - parser = OptionParser(option_class=eng_option) - parser.add_option("-w", "--which", type="int", default=0, - help="select which USRP (0, 1, ...) default is %default", - metavar="NUM") - parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, - help="select USRP Rx side A or B (default=first one with a daughterboard)") - parser.add_option("-d", "--decim", type="int", default=16, - help="set fgpa decimation rate to DECIM [default=%default]") - parser.add_option("-f", "--freq", type="eng_float", default=None, - help="set frequency to FREQ", metavar="FREQ") - parser.add_option("-g", "--gain", type="eng_float", default=None, - help="set gain in dB (default is midpoint)") - parser.add_option("-W", "--waterfall", action="store_true", default=False, - help="Enable waterfall display") - parser.add_option("-8", "--width-8", action="store_true", default=False, - help="Enable 8-bit samples across USB") - parser.add_option("-S", "--oscilloscope", action="store_true", default=False, - help="Enable oscilloscope display") - (options, args) = parser.parse_args() - if len(args) != 0: - parser.print_help() - sys.exit(1) - - self.show_debug_info = True - - # build the graph - - self.u = usrp.source_c(which=options.which, decim_rate=options.decim) - if options.rx_subdev_spec is None: - options.rx_subdev_spec = pick_subdevice(self.u) - self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) - - if options.width_8: - width = 8 - shift = 8 - format = self.u.make_format(width, shift) - print "format =", hex(format) - r = self.u.set_format(format) - print "set_format =", r - - # determine the daughterboard subdevice we're using - self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) - - input_rate = self.u.adc_freq() / self.u.decim_rate() - - if options.waterfall: - self.scope = \ - waterfallsink.waterfall_sink_c (self, panel, fft_size=1024, sample_rate=input_rate) - elif options.oscilloscope: - self.scope = scopesink.scope_sink_c(self, panel, sample_rate=input_rate) - else: - self.scope = fftsink.fft_sink_c (self, panel, fft_size=1024, sample_rate=input_rate) - - self.connect(self.u, self.scope) - - self._build_gui(vbox) - - # set initial values - - if options.gain is None: - # if no gain was specified, use the mid-point in dB - g = self.subdev.gain_range() - options.gain = float(g[0]+g[1])/2 - - if options.freq is None: - # if no freq was specified, use the mid-point - r = self.subdev.freq_range() - options.freq = float(r[0]+r[1])/2 - - self.set_gain(options.gain) - - if self.show_debug_info: - self.myform['decim'].set_value(self.u.decim_rate()) - self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) - self.myform['dbname'].set_value(self.subdev.name()) - self.myform['baseband'].set_value(0) - self.myform['ddc'].set_value(0) - - if not(self.set_freq(options.freq)): - self._set_status_msg("Failed to set initial frequency") - - def _set_status_msg(self, msg): - self.frame.GetStatusBar().SetStatusText(msg, 0) - - def _build_gui(self, vbox): - - def _form_set_freq(kv): - return self.set_freq(kv['freq']) - - vbox.Add(self.scope.win, 10, wx.EXPAND) - - # add control area at the bottom - self.myform = myform = form.form() - hbox = wx.BoxSizer(wx.HORIZONTAL) - hbox.Add((5,0), 0, 0) - myform['freq'] = form.float_field( - parent=self.panel, sizer=hbox, label="Center freq", weight=1, - callback=myform.check_input_and_call(_form_set_freq, self._set_status_msg)) - - hbox.Add((5,0), 0, 0) - g = self.subdev.gain_range() - myform['gain'] = form.slider_field(parent=self.panel, sizer=hbox, label="Gain", - weight=3, - min=int(g[0]), max=int(g[1]), - callback=self.set_gain) - - hbox.Add((5,0), 0, 0) - vbox.Add(hbox, 0, wx.EXPAND) - - self._build_subpanel(vbox) - - def _build_subpanel(self, vbox_arg): - # build a secondary information panel (sometimes hidden) - - # FIXME figure out how to have this be a subpanel that is always - # created, but has its visibility controlled by foo.Show(True/False) - - def _form_set_decim(kv): - return self.set_decim(kv['decim']) - - if not(self.show_debug_info): - return - - panel = self.panel - vbox = vbox_arg - myform = self.myform - - #panel = wx.Panel(self.panel, -1) - #vbox = wx.BoxSizer(wx.VERTICAL) - - hbox = wx.BoxSizer(wx.HORIZONTAL) - hbox.Add((5,0), 0) - - myform['decim'] = form.int_field( - parent=panel, sizer=hbox, label="Decim", - callback=myform.check_input_and_call(_form_set_decim, self._set_status_msg)) - - hbox.Add((5,0), 1) - myform['fs@usb'] = form.static_float_field( - parent=panel, sizer=hbox, label="Fs@USB") - - hbox.Add((5,0), 1) - myform['dbname'] = form.static_text_field( - parent=panel, sizer=hbox) - - hbox.Add((5,0), 1) - myform['baseband'] = form.static_float_field( - parent=panel, sizer=hbox, label="Analog BB") - - hbox.Add((5,0), 1) - myform['ddc'] = form.static_float_field( - parent=panel, sizer=hbox, label="DDC") - - hbox.Add((5,0), 0) - vbox.Add(hbox, 0, wx.EXPAND) - - - def set_freq(self, target_freq): - """ - Set the center frequency we're interested in. - - @param target_freq: frequency in Hz - @rypte: bool - - Tuning is a two step process. First we ask the front-end to - tune as close to the desired frequency as it can. Then we use - the result of that operation and our target_frequency to - determine the value for the digital down converter. - """ - r = self.u.tune(0, self.subdev, target_freq) - - if r: - self.myform['freq'].set_value(target_freq) # update displayed value - if self.show_debug_info: - self.myform['baseband'].set_value(r.baseband_freq) - self.myform['ddc'].set_value(r.dxc_freq) - return True - - return False - - def set_gain(self, gain): - self.myform['gain'].set_value(gain) # update displayed value - self.subdev.set_gain(gain) - - def set_decim(self, decim): - ok = self.u.set_decim_rate(decim) - if not ok: - print "set_decim failed" - input_rate = self.u.adc_freq() / self.u.decim_rate() - self.scope.set_sample_rate(input_rate) - if self.show_debug_info: # update displayed values - self.myform['decim'].set_value(self.u.decim_rate()) - self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) - return ok - -def main (): - app = stdgui.stdapp(app_flow_graph, "USRP FFT", nstatus=1) - app.MainLoop() - -if __name__ == '__main__': - main () diff --git a/gnuradio-examples/python/usrp/usrp_fft_old.py b/gnuradio-examples/python/usrp/usrp_fft_old.py deleted file mode 100755 index 5edb372b98..0000000000 --- a/gnuradio-examples/python/usrp/usrp_fft_old.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from gnuradio import gr, gru -from gnuradio import usrp -from gnuradio import eng_notation -from gnuradio.eng_option import eng_option -from gnuradio.wxgui import stdgui, fftsink, scopesink -from optparse import OptionParser -import wx - -class app_flow_graph (stdgui.gui_flow_graph): - def __init__(self, frame, panel, vbox, argv): - stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv) - - self.frame = frame - self.panel = panel - - parser = OptionParser (option_class=eng_option) - parser.add_option ("-d", "--decim", type="int", default=16, - help="set fgpa decimation rate to DECIM") - parser.add_option ("-c", "--ddc-freq", type="eng_float", default=0, - help="set Rx DDC frequency to FREQ", metavar="FREQ") - parser.add_option ("-m", "--mux", type="intx", default=0x32103210, - help="set fpga FR_RX_MUX register to MUX") - parser.add_option ("-g", "--gain", type="eng_float", default=0, - help="set Rx PGA gain in dB (default 0 dB)") - (options, args) = parser.parse_args () - - self.u = usrp.source_c (0, options.decim, 1, gru.hexint(options.mux), 0) - self.u.set_rx_freq (0, options.ddc_freq) - - self.u.set_pga (0, options.gain) - self.u.set_pga (1, options.gain) - - self.u.set_verbose (0) - - input_rate = self.u.adc_freq () / self.u.decim_rate () - - fft = fftsink.fft_sink_c (self, panel, fft_size=1024, sample_rate=input_rate) - #fft = fftsink.fft_sink_c (self, panel, fft_size=1024, fft_rate=50, sample_rate=input_rate) - self.connect (self.u, fft) - vbox.Add (fft.win, 10, wx.EXPAND) - - if 0: - c2f_1 = gr.complex_to_float () - scope = scopesink.scope_sink_f (self, panel, "Rx Data", input_rate) - vbox.Add (scope.win, 4, wx.EXPAND) - - self.connect (self.u,c2f_1) - self.connect ((c2f_1, 0), (scope, 0)) - self.connect ((c2f_1, 1), (scope, 1)) - - # build small control area at bottom - hbox = wx.BoxSizer (wx.HORIZONTAL) - hbox.Add ((1, 1), 1, wx.EXPAND) - hbox.Add (wx.StaticText (panel, -1, "Set ddc freq: "), 0, wx.ALIGN_CENTER) - self.tc_freq = wx.TextCtrl (panel, -1, "", style=wx.TE_PROCESS_ENTER) - hbox.Add (self.tc_freq, 0, wx.ALIGN_CENTER) - wx.EVT_TEXT_ENTER (self.tc_freq, self.tc_freq.GetId(), self.handle_text_enter) - hbox.Add ((1, 1), 1, wx.EXPAND) - # add it to the main vbox - vbox.Add (hbox, 0, wx.EXPAND) - - self.update_status_bar () - - def handle_text_enter (self, event): - str = event.GetString () - self.tc_freq.Clear () - self.u.set_rx_freq (0, eng_notation.str_to_num (str)) - self.update_status_bar () - - def update_status_bar (self): - ddc_freq = self.u.rx_freq (0) - decim_rate = self.u.decim_rate () - sample_rate = self.u.adc_freq () / decim_rate - msg = "decim: %d %sS/s DDC: %s" % ( - decim_rate, - eng_notation.num_to_str (sample_rate), - eng_notation.num_to_str (ddc_freq)) - - self.frame.GetStatusBar().SetStatusText (msg, 1) - - - -def main (): - app = stdgui.stdapp (app_flow_graph, "USRP FFT") - app.MainLoop () - -if __name__ == '__main__': - main () diff --git a/gnuradio-examples/python/usrp/usrp_oscope.py b/gnuradio-examples/python/usrp/usrp_oscope.py deleted file mode 100755 index 5d71492816..0000000000 --- a/gnuradio-examples/python/usrp/usrp_oscope.py +++ /dev/null @@ -1,252 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2005,2006 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -# print "Loading revised usrp_oscope with additional options for scopesink..." - -from gnuradio import gr, gru -from gnuradio import usrp -from gnuradio import eng_notation -from gnuradio.eng_option import eng_option -from gnuradio.wxgui import stdgui, fftsink, waterfallsink, scopesink, form, slider -from optparse import OptionParser -import wx -import sys - - -def pick_subdevice(u): - """ - The user didn't specify a subdevice on the command line. - If there's a daughterboard on A, select A. - If there's a daughterboard on B, select B. - Otherwise, select A. - """ - if u.db[0][0].dbid() >= 0: # dbid is < 0 if there's no d'board or a problem - return (0, 0) - if u.db[1][0].dbid() >= 0: - return (1, 0) - return (0, 0) - - -class app_flow_graph(stdgui.gui_flow_graph): - def __init__(self, frame, panel, vbox, argv): - stdgui.gui_flow_graph.__init__(self) - - self.frame = frame - self.panel = panel - - parser = OptionParser(option_class=eng_option) - parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, - help="select USRP Rx side A or B (default=first one with a daughterboard)") - parser.add_option("-d", "--decim", type="int", default=16, - help="set fgpa decimation rate to DECIM [default=%default]") - parser.add_option("-f", "--freq", type="eng_float", default=None, - help="set frequency to FREQ", metavar="FREQ") - parser.add_option("-g", "--gain", type="eng_float", default=None, - help="set gain in dB (default is midpoint)") - parser.add_option("-8", "--width-8", action="store_true", default=False, - help="Enable 8-bit samples across USB") - parser.add_option("-n", "--frame-decim", type="int", default=1, - help="set oscope frame decimation factor to n [default=1]") - parser.add_option("-v", "--v-scale", type="eng_float", default=1000, - help="set oscope initial V/div to SCALE [default=%default]") - parser.add_option("-t", "--t-scale", type="eng_float", default=49e-6, - help="set oscope initial s/div to SCALE [default=50us]") - (options, args) = parser.parse_args() - if len(args) != 0: - parser.print_help() - sys.exit(1) - - self.show_debug_info = True - - # build the graph - - self.u = usrp.source_c(decim_rate=options.decim) - if options.rx_subdev_spec is None: - options.rx_subdev_spec = pick_subdevice(self.u) - self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) - - if options.width_8: - width = 8 - shift = 8 - format = self.u.make_format(width, shift) - #print "format =", hex(format) - r = self.u.set_format(format) - #print "set_format =", r - - # determine the daughterboard subdevice we're using - self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) - - input_rate = self.u.adc_freq() / self.u.decim_rate() - - self.scope = scopesink.scope_sink_c(self, panel, sample_rate=input_rate, - frame_decim=options.frame_decim, - v_scale=options.v_scale, - t_scale=options.t_scale) - self.connect(self.u, self.scope) - - self._build_gui(vbox) - - # set initial values - - if options.gain is None: - # if no gain was specified, use the mid-point in dB - g = self.subdev.gain_range() - options.gain = float(g[0]+g[1])/2 - - if options.freq is None: - # if no freq was specified, use the mid-point - r = self.subdev.freq_range() - options.freq = float(r[0]+r[1])/2 - - self.set_gain(options.gain) - - if self.show_debug_info: - self.myform['decim'].set_value(self.u.decim_rate()) - self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) - self.myform['dbname'].set_value(self.subdev.name()) - self.myform['baseband'].set_value(0) - self.myform['ddc'].set_value(0) - - if not(self.set_freq(options.freq)): - self._set_status_msg("Failed to set initial frequency") - - - def _set_status_msg(self, msg): - self.frame.GetStatusBar().SetStatusText(msg, 0) - - def _build_gui(self, vbox): - - def _form_set_freq(kv): - return self.set_freq(kv['freq']) - - vbox.Add(self.scope.win, 10, wx.EXPAND) - - # add control area at the bottom - self.myform = myform = form.form() - hbox = wx.BoxSizer(wx.HORIZONTAL) - hbox.Add((5,0), 0, 0) - myform['freq'] = form.float_field( - parent=self.panel, sizer=hbox, label="Center freq", weight=1, - callback=myform.check_input_and_call(_form_set_freq, self._set_status_msg)) - - hbox.Add((5,0), 0, 0) - g = self.subdev.gain_range() - myform['gain'] = form.slider_field(parent=self.panel, sizer=hbox, label="Gain", - weight=3, - min=int(g[0]), max=int(g[1]), - callback=self.set_gain) - - hbox.Add((5,0), 0, 0) - vbox.Add(hbox, 0, wx.EXPAND) - - self._build_subpanel(vbox) - - def _build_subpanel(self, vbox_arg): - # build a secondary information panel (sometimes hidden) - - # FIXME figure out how to have this be a subpanel that is always - # created, but has its visibility controlled by foo.Show(True/False) - - def _form_set_decim(kv): - return self.set_decim(kv['decim']) - - if not(self.show_debug_info): - return - - panel = self.panel - vbox = vbox_arg - myform = self.myform - - #panel = wx.Panel(self.panel, -1) - #vbox = wx.BoxSizer(wx.VERTICAL) - - hbox = wx.BoxSizer(wx.HORIZONTAL) - hbox.Add((5,0), 0) - - myform['decim'] = form.int_field( - parent=panel, sizer=hbox, label="Decim", - callback=myform.check_input_and_call(_form_set_decim, self._set_status_msg)) - - hbox.Add((5,0), 1) - myform['fs@usb'] = form.static_float_field( - parent=panel, sizer=hbox, label="Fs@USB") - - hbox.Add((5,0), 1) - myform['dbname'] = form.static_text_field( - parent=panel, sizer=hbox) - - hbox.Add((5,0), 1) - myform['baseband'] = form.static_float_field( - parent=panel, sizer=hbox, label="Analog BB") - - hbox.Add((5,0), 1) - myform['ddc'] = form.static_float_field( - parent=panel, sizer=hbox, label="DDC") - - hbox.Add((5,0), 0) - vbox.Add(hbox, 0, wx.EXPAND) - - - def set_freq(self, target_freq): - """ - Set the center frequency we're interested in. - - @param target_freq: frequency in Hz - @rypte: bool - - Tuning is a two step process. First we ask the front-end to - tune as close to the desired frequency as it can. Then we use - the result of that operation and our target_frequency to - determine the value for the digital down converter. - """ - r = usrp.tune(self.u, 0, self.subdev, target_freq) - - if r: - self.myform['freq'].set_value(target_freq) # update displayed value - if self.show_debug_info: - self.myform['baseband'].set_value(r.baseband_freq) - self.myform['ddc'].set_value(r.dxc_freq) - return True - - return False - - def set_gain(self, gain): - self.myform['gain'].set_value(gain) # update displayed value - self.subdev.set_gain(gain) - - def set_decim(self, decim): - ok = self.u.set_decim_rate(decim) - if not ok: - print "set_decim failed" - input_rate = self.u.adc_freq() / self.u.decim_rate() - self.scope.set_sample_rate(input_rate) - if self.show_debug_info: # update displayed values - self.myform['decim'].set_value(self.u.decim_rate()) - self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) - return ok - -def main (): - app = stdgui.stdapp(app_flow_graph, "USRP O'scope", nstatus=1) - app.MainLoop() - -if __name__ == '__main__': - main () diff --git a/gnuradio-examples/python/usrp/usrp_rx_cfile.py b/gnuradio-examples/python/usrp/usrp_rx_cfile.py deleted file mode 100755 index 306e101d35..0000000000 --- a/gnuradio-examples/python/usrp/usrp_rx_cfile.py +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/env python - -""" -Read samples from the USRP and write to file formatted as binary -outputs single precision complex float values or complex short values (interleaved 16 bit signed short integers). - -""" - -from gnuradio import gr, eng_notation -from gnuradio import audio -from gnuradio import usrp -from gnuradio.eng_option import eng_option -from optparse import OptionParser - -class my_graph(gr.flow_graph): - - def __init__(self): - gr.flow_graph.__init__(self) - - usage="%prog: [options] output_filename" - parser = OptionParser(option_class=eng_option, usage=usage) - parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0), - help="select USRP Rx side A or B (default=A)") - parser.add_option("-d", "--decim", type="int", default=16, - help="set fgpa decimation rate to DECIM [default=%default]") - parser.add_option("-f", "--freq", type="eng_float", default=None, - help="set frequency to FREQ", metavar="FREQ") - parser.add_option("-g", "--gain", type="eng_float", default=None, - help="set gain in dB (default is midpoint)") - parser.add_option("-8", "--width-8", action="store_true", default=False, - help="Enable 8-bit samples across USB") - parser.add_option( "--no-hb", action="store_true", default=False, - help="don't use halfband filter in usrp") - parser.add_option( "-s","--output-shorts", action="store_true", default=False, - help="output interleaved shorts in stead of complex floats") - parser.add_option("-N", "--nsamples", type="eng_float", default=None, - help="number of samples to collect [default=+inf]") - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] - - if options.freq is None: - parser.print_help() - sys.stderr.write('You must specify the frequency with -f FREQ\n'); - raise SystemExit, 1 - - # build the graph - if options.no_hb or (options.decim<8): - self.fpga_filename="std_4rx_0tx.rbf" #Min decimation of this firmware is 4. contains 4 Rx paths without halfbands and 0 tx paths. - if options.output_shorts: - self.u = usrp.source_s(decim_rate=options.decim,fpga_filename=self.fpga_filename) - else: - self.u = usrp.source_c(decim_rate=options.decim,fpga_filename=self.fpga_filename) - else: - #standard fpga firmware "std_2rxhb_2tx.rbf" contains 2 Rx paths with halfband filters and 2 tx paths (the default) min decimation 8 - if options.output_shorts: - self.u = usrp.source_s(decim_rate=options.decim) - else: - self.u = usrp.source_c(decim_rate=options.decim) - if options.width_8: - sample_width = 8 - sample_shift = 8 - format = self.u.make_format(sample_width, sample_shift) - r = self.u.set_format(format) - if options.output_shorts: - self.dst = gr.file_sink(gr.sizeof_short, filename) - else: - self.dst = gr.file_sink(gr.sizeof_gr_complex, filename) - if options.nsamples is None: - self.connect(self.u, self.dst) - else: - if options.output_shorts: - self.head = gr.head(gr.sizeof_short, int(options.nsamples)*2) - else: - self.head = gr.head(gr.sizeof_gr_complex, int(options.nsamples)) - self.connect(self.u, self.head, self.dst) - - if options.rx_subdev_spec is None: - options.rx_subdev_spec = usrp.pick_rx_subdevice(self.u) - self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) - - # determine the daughterboard subdevice we're using - self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) - print "Using RX d'board %s" % (self.subdev.side_and_name(),) - input_rate = self.u.adc_freq() / self.u.decim_rate() - print "USB sample rate %s" % (eng_notation.num_to_str(input_rate)) - - if options.gain is None: - # if no gain was specified, use the mid-point in dB - g = self.subdev.gain_range() - options.gain = float(g[0]+g[1])/2 - - self.subdev.set_gain(options.gain) - - r = self.u.tune(0, self.subdev, options.freq) - if not r: - sys.stderr.write('Failed to set frequency\n') - raise SystemExit, 1 - - -if __name__ == '__main__': - try: - my_graph().run() - except KeyboardInterrupt: - pass diff --git a/gnuradio-examples/python/usrp/usrp_rx_nogui.py b/gnuradio-examples/python/usrp/usrp_rx_nogui.py deleted file mode 100755 index b33d626e28..0000000000 --- a/gnuradio-examples/python/usrp/usrp_rx_nogui.py +++ /dev/null @@ -1,186 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr, gru, usrp, optfir, audio, eng_notation, blks -from gnuradio.eng_option import eng_option -from optparse import OptionParser - -""" -This example application demonstrates receiving and demodulating -different types of signals using the USRP. - -A receive chain is built up of the following signal processing -blocks: - -USRP - Daughter board source generating complex baseband signal. -CHAN - Low pass filter to select channel bandwidth -RFSQL - RF squelch zeroing output when input power below threshold -AGC - Automatic gain control leveling signal at [-1.0, +1.0] -DEMOD - Demodulation block appropriate to selected signal type. - This converts the complex baseband to real audio frequencies, - and applies an appropriate low pass decimating filter. -CTCSS - Optional tone squelch zeroing output when tone is not present. -RSAMP - Resampler block to convert audio sample rate to user specified - sound card output rate. -AUDIO - Audio sink for playing final output to speakers. - -The following are required command line parameters: - --f FREQ USRP receive frequency --m MOD Modulation type, select from AM, FM, or WFM - -The following are optional command line parameters: - --R SUBDEV Daughter board specification, defaults to first found --c FREQ Calibration offset. Gets added to receive frequency. - Defaults to 0.0 Hz. --g GAIN Daughterboard gain setting. Defaults to mid-range. --o RATE Sound card output rate. Defaults to 32000. Useful if - your sound card only accepts particular sample rates. --r RFSQL RF squelch in db. Defaults to -50.0. --p FREQ CTCSS frequency. Opens squelch when tone is present. - -Once the program is running, ctrl-break (Ctrl-C) stops operation. - -Please see fm_demod.py and am_demod.py for details of the demodulation -blocks. -""" - -# (usrp_decim, channel_decim, audio_decim, channel_pass, channel_stop, demod) -demod_params = { - 'AM' : (250, 16, 1, 5000, 8000, blks.demod_10k0a3e_cf), - 'FM' : (250, 8, 4, 8000, 9000, blks.demod_20k0f3e_cf), - 'WFM' : (250, 1, 8, 90000, 100000, blks.demod_200kf3e_cf) - } - -class usrp_source_c(gr.hier_block): - """ - Create a USRP source object supplying complex floats. - - Selects user supplied subdevice or chooses first available one. - - Calibration value is the offset from the tuned frequency to - the actual frequency. - """ - def __init__(self, fg, subdev_spec, decim, gain=None, calibration=0.0): - self._decim = decim - self._src = usrp.source_c() - if subdev_spec is None: - subdev_spec = usrp.pick_rx_subdevice(self._src) - self._subdev = usrp.selected_subdev(self._src, subdev_spec) - self._src.set_mux(usrp.determine_rx_mux_value(self._src, subdev_spec)) - self._src.set_decim_rate(self._decim) - - # If no gain specified, set to midrange - if gain is None: - g = self._subdev.gain_range() - gain = (g[0]+g[1])/2.0 - - self._subdev.set_gain(gain) - self._cal = calibration - gr.hier_block.__init__(self, fg, self._src, self._src) - - def tune(self, freq): - result = usrp.tune(self._src, 0, self._subdev, freq+self._cal) - # TODO: deal with residual - - def rate(self): - return self._src.adc_rate()/self._decim - -class app_flow_graph(gr.flow_graph): - def __init__(self, options, args): - gr.flow_graph.__init__(self) - self.options = options - self.args = args - - (usrp_decim, channel_decim, audio_decim, - channel_pass, channel_stop, demod) = demod_params[options.modulation] - - USRP = usrp_source_c(self, # Flow graph - options.rx_subdev_spec, # Daugherboard spec - usrp_decim, # IF decimation ratio - options.gain, # Receiver gain - options.calibration) # Frequency offset - USRP.tune(options.frequency) - - if_rate = USRP.rate() - channel_rate = if_rate // channel_decim - audio_rate = channel_rate // audio_decim - - CHAN_taps = optfir.low_pass(1.0, # Filter gain - if_rate, # Sample rate - channel_pass, # One sided modulation bandwidth - channel_stop, # One sided channel bandwidth - 0.1, # Passband ripple - 60) # Stopband attenuation - - CHAN = gr.freq_xlating_fir_filter_ccf(channel_decim, # Decimation rate - CHAN_taps, # Filter taps - 0.0, # Offset frequency - if_rate) # Sample rate - - RFSQL = gr.pwr_squelch_cc(options.rf_squelch, # Power threshold - 125.0/channel_rate, # Time constant - channel_rate/20, # 50ms rise/fall - False) # Zero, not gate output - - AGC = gr.agc_cc(1.0/channel_rate, # Time constant - 1.0, # Reference power - 1.0, # Initial gain - 1.0) # Maximum gain - - DEMOD = demod(self, channel_rate, audio_decim) - - # From RF to audio - self.connect(USRP, CHAN, RFSQL, AGC, DEMOD) - - # Optionally add CTCSS and RSAMP if needed - tail = DEMOD - if options.ctcss != None and options.ctcss > 60.0: - CTCSS = gr.ctcss_squelch_ff(audio_rate, # Sample rate - options.ctcss) # Squelch tone - self.connect(DEMOD, CTCSS) - tail = CTCSS - - if options.output_rate != audio_rate: - out_lcm = gru.lcm(audio_rate, options.output_rate) - out_interp = int(out_lcm // audio_rate) - out_decim = int(out_lcm // options.output_rate) - RSAMP = blks.rational_resampler_fff(self, out_interp, out_decim) - self.connect(tail, RSAMP) - tail = RSAMP - - # Send to default audio output - AUDIO = audio.sink(options.output_rate, "") - self.connect(tail, AUDIO) - -def main(): - parser = OptionParser(option_class=eng_option) - parser.add_option("-f", "--frequency", type="eng_float", - help="set receive frequency to Hz", metavar="Hz") - parser.add_option("-R", "--rx-subdev-spec", type="subdev", - help="select USRP Rx side A or B", metavar="SUBDEV") - parser.add_option("-c", "--calibration", type="eng_float", default=0.0, - help="set frequency offset to Hz", metavar="Hz") - parser.add_option("-g", "--gain", type="int", default=None, - help="set RF gain", metavar="dB") - parser.add_option("-m", "--modulation", type="choice", choices=('AM','FM','WFM'), - help="set modulation type (AM,FM)", metavar="TYPE") - parser.add_option("-o", "--output-rate", type="int", default=32000, - help="set audio output rate to RATE", metavar="RATE") - parser.add_option("-r", "--rf-squelch", type="eng_float", default=-50.0, - help="set RF squelch to dB", metavar="dB") - parser.add_option("-p", "--ctcss", type="float", - help="set CTCSS squelch to FREQ", metavar="FREQ") - (options, args) = parser.parse_args() - - if options.frequency < 1e6: - options.frequency *= 1e6 - - fg = app_flow_graph(options, args) - try: - fg.run() - except KeyboardInterrupt: - pass - -if __name__ == "__main__": - main() diff --git a/gnuradio-examples/python/usrp/usrp_siggen.py b/gnuradio-examples/python/usrp/usrp_siggen.py deleted file mode 100755 index 7f5285885b..0000000000 --- a/gnuradio-examples/python/usrp/usrp_siggen.py +++ /dev/null @@ -1,180 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr, gru -from gnuradio import usrp -from gnuradio.eng_option import eng_option -from gnuradio import eng_notation -from optparse import OptionParser -import sys - - -class my_graph(gr.flow_graph): - def __init__ (self): - gr.flow_graph.__init__(self) - - # controllable values - self.interp = 64 - self.waveform_type = gr.GR_SIN_WAVE - self.waveform_ampl = 16000 - self.waveform_freq = 100.12345e3 - self.waveform_offset = 0 - self._instantiate_blocks () - self.set_waveform_type (self.waveform_type) - - def usb_freq (self): - return self.u.dac_freq() / self.interp - - def usb_throughput (self): - return self.usb_freq () * 4 - - def set_waveform_type (self, type): - ''' - valid waveform types are: gr.GR_SIN_WAVE, gr.GR_CONST_WAVE, - gr.GR_UNIFORM and gr.GR_GAUSSIAN - ''' - self._configure_graph (type) - self.waveform_type = type - - def set_waveform_ampl (self, ampl): - self.waveform_ampl = ampl - self.siggen.set_amplitude (ampl) - self.noisegen.set_amplitude (ampl) - - def set_waveform_freq (self, freq): - self.waveform_freq = freq - self.siggen.set_frequency (freq) - - def set_waveform_offset (self, offset): - self.waveform_offset = offset - self.siggen.set_offset (offset) - - def set_interpolator (self, interp): - self.interp = interp - self.siggen.set_sampling_freq (self.usb_freq ()) - self.u.set_interp_rate (interp) - - def _instantiate_blocks (self): - self.src = None - self.u = usrp.sink_c (0, self.interp) - - self.siggen = gr.sig_source_c (self.usb_freq (), - gr.GR_SIN_WAVE, - self.waveform_freq, - self.waveform_ampl, - self.waveform_offset) - - self.noisegen = gr.noise_source_c (gr.GR_UNIFORM, - self.waveform_ampl) - - # self.file_sink = gr.file_sink (gr.sizeof_gr_complex, "siggen.dat") - - def _configure_graph (self, type): - was_running = self.is_running () - if was_running: - self.stop () - self.disconnect_all () - if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE: - self.connect (self.siggen, self.u) - # self.connect (self.siggen, self.file_sink) - self.siggen.set_waveform (type) - self.src = self.siggen - elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN: - self.connect (self.noisegen, self.u) - self.noisegen.set_type (type) - self.src = self.noisegen - else: - raise ValueError, type - if was_running: - self.start () - - def set_freq(self, target_freq): - """ - Set the center frequency we're interested in. - - @param target_freq: frequency in Hz - @rypte: bool - - Tuning is a two step process. First we ask the front-end to - tune as close to the desired frequency as it can. Then we use - the result of that operation and our target_frequency to - determine the value for the digital up converter. - """ - r = self.u.tune(self.subdev._which, self.subdev, target_freq) - if r: - #print "r.baseband_freq =", eng_notation.num_to_str(r.baseband_freq) - #print "r.dxc_freq =", eng_notation.num_to_str(r.dxc_freq) - #print "r.residual_freq =", eng_notation.num_to_str(r.residual_freq) - #print "r.inverted =", r.inverted - return True - - return False - - - -def main (): - parser = OptionParser (option_class=eng_option) - parser.add_option ("-T", "--tx-subdev-spec", type="subdev", default=(0, 0), - help="select USRP Tx side A or B") - parser.add_option ("-f", "--rf-freq", type="eng_float", default=None, - help="set RF center frequency to FREQ") - parser.add_option ("-i", "--interp", type="int", default=64, - help="set fgpa interpolation rate to INTERP [default=%default]") - - parser.add_option ("--sine", dest="type", action="store_const", const=gr.GR_SIN_WAVE, - help="generate a complex sinusoid [default]", default=gr.GR_SIN_WAVE) - parser.add_option ("--const", dest="type", action="store_const", const=gr.GR_CONST_WAVE, - help="generate a constant output") - parser.add_option ("--gaussian", dest="type", action="store_const", const=gr.GR_GAUSSIAN, - help="generate Gaussian random output") - parser.add_option ("--uniform", dest="type", action="store_const", const=gr.GR_UNIFORM, - help="generate Uniform random output") - - parser.add_option ("-w", "--waveform-freq", type="eng_float", default=100e3, - 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 ("-o", "--offset", type="eng_float", default=0, - help="set waveform offset to OFFSET [default=%default]") - (options, args) = parser.parse_args () - - if len(args) != 0: - parser.print_help() - raise SystemExit - - if options.rf_freq is None: - sys.stderr.write("usrp_siggen: must specify RF center frequency with -f RF_FREQ\n") - parser.print_help() - raise SystemExit - - fg = my_graph() - fg.set_interpolator (options.interp) - fg.set_waveform_type (options.type) - fg.set_waveform_freq (options.waveform_freq) - fg.set_waveform_ampl (options.amplitude) - fg.set_waveform_offset (options.offset) - - # determine the daughterboard subdevice we're using - if options.tx_subdev_spec is None: - options.tx_subdev_spec = usrp.pick_tx_subdevice(fg.u) - - m = usrp.determine_tx_mux_value(fg.u, options.tx_subdev_spec) - #print "mux = %#04x" % (m,) - fg.u.set_mux(m) - fg.subdev = usrp.selected_subdev(fg.u, options.tx_subdev_spec) - print "Using TX d'board %s" % (fg.subdev.side_and_name(),) - - fg.subdev.set_gain(fg.subdev.gain_range()[1]) # set max Tx gain - - if not fg.set_freq(options.rf_freq): - sys.stderr.write('Failed to set RF frequency\n') - raise SystemExit - - fg.subdev.set_enable(True) # enable transmitter - - try: - fg.run() - except KeyboardInterrupt: - pass - -if __name__ == '__main__': - main () -- cgit v1.2.3