Skip to content

Instantly share code, notes, and snippets.

@tfcollins
Created November 29, 2023 00:06
Show Gist options
  • Save tfcollins/3fe4e0550dd4714dcbc7f7735ab4e2e8 to your computer and use it in GitHub Desktop.
Save tfcollins/3fe4e0550dd4714dcbc7f7735ab4e2e8 to your computer and use it in GitHub Desktop.
import iio
import matplotlib.pyplot as plt
import numpy as np
from scipy import signal
import time
def test_complex_buffer():
ctx = iio.Context('ip:analog.local')
dev = ctx.find_device('cf-ad9361-lpc')
# chan = dev.find_channel('voltage10', is_output=True)
mask = iio.ChannelsMask(dev)
mask.channels = [dev.channels[0], dev.channels[1]]
buf = iio.Buffer(dev, mask)
stream = iio.Stream(buf, 1024)
fs = 1e6
for r in range(20):
block = next(stream)
# Single buffer read
# x = np.frombuffer(block.read(), dtype=np.int16)
# x = x[0::2] + 1j*x[1::2]
# Buffer read by channel
re = mask.channels[0].read(block)
re = np.frombuffer(re, dtype=np.int16)
im = mask.channels[1].read(block)
im = np.frombuffer(im, dtype=np.int16)
x = re + 1j*im
f, Pxx_den = signal.periodogram(x, fs)
plt.clf()
plt.semilogy(f, Pxx_den)
plt.ylim([1e-7, 1e2])
plt.xlabel("frequency [Hz]")
plt.ylabel("PSD [V**2/Hz]")
plt.draw()
plt.pause(0.05)
time.sleep(0.1)
plt.show()
if __name__ == '__main__':
test_complex_buffer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment