From 83d495920ad1b1b2fe847c1b5bbf2d2c3148686f Mon Sep 17 00:00:00 2001 From: Brendan Haines Date: Sun, 10 Nov 2024 12:45:31 -0700 Subject: [PATCH] add pluto example from adi --- charon_vna/pluto_example.py | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 charon_vna/pluto_example.py diff --git a/charon_vna/pluto_example.py b/charon_vna/pluto_example.py new file mode 100644 index 0000000..ae855c3 --- /dev/null +++ b/charon_vna/pluto_example.py @@ -0,0 +1,63 @@ +# Copyright (C) 2019 Analog Devices, Inc. +# +# SPDX short identifier: ADIBSD + + +# I'm not sure why but sometimes I need to run this once to make the rest of my scripts work. +# Probably just me running things manually out of order or something but I'm throwing this in here until I verify. + +import time + +import adi +import matplotlib.pyplot as plt +import numpy as np +from scipy import signal + +# Create radio +sdr = adi.Pluto(uri="ip:192.168.3.1") + +# Configure properties +sdr.rx_rf_bandwidth = 4000000 +sdr.rx_lo = 2000000000 +sdr.tx_lo = 2000000000 +sdr.tx_cyclic_buffer = True +sdr.tx_hardwaregain_chan0 = -30 +sdr.gain_control_mode_chan0 = "slow_attack" + +# Read properties +print("RX LO %s" % (sdr.rx_lo)) + +# Create a sinewave waveform +fs = int(sdr.sample_rate) +print(fs) +N = 1024 +fc = int(-3000000 / (fs / N)) * (fs / N) +ts = 1 / float(fs) +t = np.arange(0, N * ts, ts) +i = np.cos(2 * np.pi * t * fc) * 2**14 +q = np.sin(2 * np.pi * t * fc) * 2**14 +iq = i + 1j * q + +# Send data +sdr.tx(iq) + +# Collect data +for r in range(20): + x = sdr.rx() + f, Pxx_den = signal.periodogram(x, fs, return_onesided=False) + plt.clf() + plt.semilogy(f, Pxx_den) + plt.ylim([1e-7, 1e2]) + plt.xlabel("frequency [Hz]") + plt.ylabel("PSD [V**2/Hz]") + plt.grid(True) + plt.draw() + plt.pause(0.05) + time.sleep(0.1) + +plt.show() + + +plt.plot(np.real(x)) +plt.plot(np.imag(x)) +plt.show()