Post Go back to editing

transmit and receive a sinewave using Z7035-AD9361 SOM based on the Python

Hello everyone, I am trying to transmit and receive a sinewave using Z7035-AD9361 SOM based on the Python script as attached.
However, I am not getting the received signal as expected. Any suggestions?

import iio
import numpy as np
import matplotlib.pyplot as plt

# User configurable
TXLO = 915000000
TXBW = 10000000
TXFS = TXBW
RXLO = TXLO
RXBW = TXBW
RXFS = TXFS

# Setup contexts
#ctx = iio.Context('ip:192.168.2.2')
ctx = iio.Context("ip:10.10.20.193")
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
ctrl.find_channel('altvoltage0',True).attrs["frequency"].value = str(int(RXLO))
ctrl.find_channel('altvoltage1',True).attrs["frequency"].value = str(int(TXLO))
ctrl.find_channel('voltage0').attrs["rf_bandwidth"].value = str(int(RXBW))
ctrl.find_channel('voltage0',True).attrs["rf_bandwidth"].value = str(int(TXBW))
ctrl.find_channel('voltage0').attrs["sampling_frequency"].value = str(int(RXFS))
ctrl.find_channel('voltage0',True).attrs["sampling_frequency"].value = str(int(TXFS))
ctrl.find_channel('voltage0').attrs['gain_control_mode'].value = 'manual'
ctrl.find_channel('voltage0',True).attrs['hardwaregain'].value = '0.0'

# Enable all IQ channels
rxadc.find_channel("voltage0").enabled = True
rxadc.find_channel("voltage1").enabled = True
txdac.find_channel("voltage0",True).enabled = True
txdac.find_channel("voltage1",True).enabled = True

# Force DAC to use DMA not DDS
txdac.find_channel('TX1_I_F1',True).attrs['raw'].value = str(0)
txdac.find_channel('TX1_Q_F1',True).attrs['raw'].value = str(0)
txdac.find_channel('TX1_I_F2',True).attrs['raw'].value = str(0)
txdac.find_channel('TX1_Q_F2',True).attrs['raw'].value = str(0)

# Create cyclic buffer for TX data
samples_per_channel = 2**15
txbuf = iio.Buffer(txdac, samples_per_channel, True)
# Create buffer for RX data
rxbuf = iio.Buffer(rxadc, samples_per_channel, False)

# Create a sinewave waveform
fc = 10000
ts = 1/float(RXFS)
t = np.arange(0, samples_per_channel*ts, ts)
#i = np.sin(2*np.pi*t*fc) *2**14
#q = np.cos(2*np.pi*t*fc) *2**14
i = np.sin(2*np.pi*t*fc)
q = np.cos(2*np.pi*t*fc)
iq = np.empty((i.size + q.size,), dtype=i.dtype)
iq[0::2] = i
iq[1::2] = q
iq = np.int16(iq)

# Send data to buffer
txbuf.write(bytearray(iq))
txbuf.push()
#time.sleep(5)

# Collect data
reals = np.array([])
imags = np.array([])

for k in range(100):
  rxbuf.refill()
  data = rxbuf.read()
  x = np.frombuffer(data,dtype=np.int16)
  reals = np.append(reals,x[0::2])
  imags = np.append(imags,x[1::2])

print(reals)
#del txbuf
#del rxbuf
# Plot
plt.figure(0)
plt.plot(reals)
#plt.plot(imags)
plt.xlabel("Samples")
plt.ylabel("Amplitude [dbFS]")
plt.title('Received')
plt.figure(1)
plt.plot(i)
#plt.plot(q)
plt.xlabel("Samples")
plt.ylabel("Amplitude")
plt.title('Transmitted')
plt.show()