aboutsummaryrefslogtreecommitdiffstats
path: root/host/examples/python/tx_waveforms.py
diff options
context:
space:
mode:
authorPaul David <paul.david@ettus.com>2017-05-02 14:10:05 -0400
committerMartin Braun <martin.braun@ettus.com>2018-06-20 19:02:32 -0500
commite74cf7635ba3360b5b7002a2f7317941f65ffa16 (patch)
tree46b63039f31c5aedf26773b4b626b2a7932999db /host/examples/python/tx_waveforms.py
parent22e24497a510c174e6de7718ad918a423d1973dd (diff)
downloaduhd-e74cf7635ba3360b5b7002a2f7317941f65ffa16.tar.gz
uhd-e74cf7635ba3360b5b7002a2f7317941f65ffa16.tar.bz2
uhd-e74cf7635ba3360b5b7002a2f7317941f65ffa16.zip
python: Separating exposed Python data structures
- Separating exposed Python data structures into logical sections - Exposes all of the multi_usrp API - Adds a layer of Python for documentation and adding helper methods - Adds improvements and fixes to the MultiUSRP object - Includes additional exposed data structures (like time_spec_t, etc.) - Add code to release the Python GIL during long C++ calls
Diffstat (limited to 'host/examples/python/tx_waveforms.py')
-rwxr-xr-xhost/examples/python/tx_waveforms.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/host/examples/python/tx_waveforms.py b/host/examples/python/tx_waveforms.py
new file mode 100755
index 000000000..6db50fa2b
--- /dev/null
+++ b/host/examples/python/tx_waveforms.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+#
+# Copyright 2017-2018 Ettus Research, a National Instruments Company
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+"""
+Generate and TX samples using a set of waveforms, and waveform characteristics
+"""
+
+import argparse
+import numpy as np
+import uhd
+
+waveforms = {
+ "sine": lambda n, tone_offset, rate: np.exp(n * 2j * np.pi * tone_offset / rate),
+ "square": lambda n, tone_offset, rate: np.sign(waveforms["sine"](n, tone_offset, rate)),
+ "const": lambda n, tone_offset, rate: 1 + 1j,
+ "ramp": lambda n, tone_offset, rate:
+ 2*(n*(tone_offset/rate) - np.floor(float(0.5 + n*(tone_offset/rate))))
+}
+
+
+def parse_args():
+ """Parse the command line arguments"""
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-a", "--args", default="", type=str)
+ parser.add_argument(
+ "-w", "--waveform", default="sine", choices=waveforms.keys(), type=str)
+ parser.add_argument("-f", "--freq", type=float, required=True)
+ parser.add_argument("-r", "--rate", default=1e6, type=float)
+ parser.add_argument("-d", "--duration", default=5.0, type=float)
+ parser.add_argument("-c", "--channels", default=0, nargs="+", type=int)
+ parser.add_argument("-g", "--gain", type=int, default=10)
+ parser.add_argument("--wave-freq", default=1e4, type=float)
+ parser.add_argument("--wave-ampl", default=0.3, type=float)
+ return parser.parse_args()
+
+
+def main():
+ """TX samples based on input arguments"""
+ args = parse_args()
+ usrp = uhd.usrp.MultiUSRP(args.args)
+ if not isinstance(args.channels, list):
+ args.channels = [args.channels]
+ data = np.array(
+ list(map(lambda n: args.wave_ampl * waveforms[args.waveform](n, args.wave_freq, args.rate),
+ np.arange(
+ int(10 * np.floor(args.rate / args.wave_freq)),
+ dtype=np.complex64))),
+ dtype=np.complex64) # One period
+
+ usrp.send_waveform(data, args.duration, args.freq, args.rate,
+ args.channels, args.gain)
+
+
+if __name__ == "__main__":
+ main()