forked from analogdevicesinc/plutosdr_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pluto.py
97 lines (83 loc) · 2.35 KB
/
pluto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
#
# Copyright (C) 2018 Analog Devices, Inc.
# Author: Travis Collins <[email protected]>
#
# Licensed under the GPL-2.
import sys
try:
import iio
except:
# By default the iio python bindings are not in path
sys.path.append('/usr/lib/python2.7/site-packages/')
import iio
import numpy as np
try:
import matplotlib.pyplot as plt
do_plots = True
except:
print("To view plots install matplotlib")
do_plots = False
# User configurable
TXLO = 1000000000
TXBW = 5000000
TXFS = 3000000
RXLO = TXLO
RXBW = TXBW
RXFS = TXFS
# Setup contexts
try:
ctx = iio.Context('ip:192.168.2.1')
except:
print("No device found")
sys.exit(0)
ctrl = ctx.find_device("ad9361-phy")
txdac = ctx.find_device("cf-ad9361-dds-core-lpc")
rxadc = ctx.find_device("cf-ad9361-lpc")
# Configure transceiver settings
rxLO = ctrl.find_channel("altvoltage0", True)
rxLO.attrs["frequency"].value = str(int(RXLO))
txLO = ctrl.find_channel("altvoltage1", True)
txLO.attrs["frequency"].value = str(int(TXLO))
tx = ctrl.find_channel("voltage0",True)
tx.attrs["rf_bandwidth"].value = str(int(RXBW))
tx.attrs["sampling_frequency"].value = str(int(RXFS))
tx.attrs['hardwaregain'].value = '-30'
rx = ctrl.find_channel("voltage0")
rx.attrs["rf_bandwidth"].value = str(int(TXBW))
rx.attrs["sampling_frequency"].value = str(int(TXFS))
rx.attrs['gain_control_mode'].value = 'slow_attack'
# Enable all IQ channels
v0 = rxadc.find_channel("voltage0")
v1 = rxadc.find_channel("voltage1")
v0.enabled = True
v1.enabled = True
# Create buffer for RX data
rxbuf = iio.Buffer(rxadc, 2**15, False)
# Enable single tone DDS
dds0 = txdac.find_channel('altvoltage0',True)
dds2 = txdac.find_channel('altvoltage2',True)
dds0.attrs['raw'].value = str(1)
dds0.attrs['frequency'].value = str(100000)
dds0.attrs['scale'].value = str(0.9)
dds0.attrs['phase'].value = str(90000)
dds2.attrs['raw'].value = str(1)
dds2.attrs['frequency'].value = str(100000)
dds2.attrs['scale'].value = str(0.9)
dds2.attrs['phase'].value = str(0)
# Collect data
reals = np.array([])
imags = np.array([])
for i in range(10):
rxbuf.refill()
data = rxbuf.read()
x = np.frombuffer(data,dtype=np.int16)
reals = np.append(reals,x[::2])
imags = np.append(imags,x[1::2])
# Plot
if do_plots:
plt.plot(reals)
plt.plot(imags)
plt.xlabel("Samples")
plt.ylabel("Amplitude [dbFS]")
plt.show()