Created
June 8, 2021 15:42
-
-
Save tfcollins/cbf2c7a563caef75eb5a80111bc92ebf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Copyright (C) 2021 Analog Devices, Inc. | |
# Author: Travis Collins <travis.collins@analog.com> | |
# | |
# 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 | |
# Setup contexts | |
try: | |
ctx = iio.Context('ip:192.168.2.1') | |
except: | |
print("No device found") | |
sys.exit(0) | |
rxadc = ctx.find_device("axi-ad9694-hpc") | |
# Enable all channels | |
v0 = rxadc.find_channel("voltage0") | |
v1 = rxadc.find_channel("voltage1") | |
v2 = rxadc.find_channel("voltage2") | |
v3 = rxadc.find_channel("voltage3") | |
v0.enabled = True | |
v1.enabled = True | |
v2.enabled = True | |
v3.enabled = True | |
# Create buffer for RX data | |
rxbuf = iio.Buffer(rxadc, 2**15, False) | |
# Collect data | |
data = [np.array([]),np.array([]),np.array([]),np.array([])] | |
for i in range(10): | |
rxbuf.refill() | |
data = rxbuf.read() | |
x = np.frombuffer(data,dtype=np.int16) | |
for k in range(4): | |
data[k] = np.append(data[k],x[k::4]) | |
# Plot | |
if do_plots: | |
plt.plot(data) | |
plt.xlabel("Samples") | |
plt.ylabel("Amplitude [ADC Codes]") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment