Post Go back to editing

IIO: RX buffer is chopped and filled with zeros. RX/TX synchronization.


First, thank you for Pluto! I think it's great, and it's a very affordable way to learn SDR. 

After some initial tests with Gnu-Radio, I went for IIO and tried to run a simple test of TX + RX with digital loopback enabled. I would like to send a TX  buffer and receive it into RX buffer. Maybe in the end I would like to get a simple VNA scenario to work. I have some issues I can't resolve. So first I will write my questions and then I will explain the details.

- How should I call IIO push/refill functions from a single thread (or I shouldn't do that)? My RX buffer gets "chopped" and filled with zeros.

- Can I synchronize TX/RX in such a way that I will know what is a delay between buffers (in terms of number of samples)?

The scenario I run is:

1. Open RX and TX on the same LO frequency with the same sampling rate.

2. Create channels/buffers needed. 

3. Enable digital loopback.

4. Prepare a sinewave using inverse fft.

5. Push TX buffer, refill RX buffer in a loop. Currently 20 iterations. 

6. Catch 10th iteration RX buffer into an array, so I can analyze it later. The idea is that it should contain TX buffer, OR TX buffer shifted by some constant offset + beginning of next TX buffer. Catching 10th iteration should neglect any effects of first/last buffers.

7. Print TX and 10th RX buffer for comparison.

(Additionally I calculate amplitude+phase of both TX and RX).

Code used:

Link it with v3 FFTW and IIO, obviously.

What I get:

As you may see in the file, the RX is offset by around 10k samples. RX contains samples starting from 10k upto 32k of TX and then 10k zeros. I didn't expect zeros there! Any ideas why is that?

Should I call push/refill from two threads for it to work? I thought that there were some internal buffers that are swapped with the buffer I push/refill so that would be short call. I know that refill/push calls may block, but is that the issue here?

Another thing: Can I synchronize TX/RX so I have a constant phase shift? It changes every time I run the code.

NOTE: In the code I use 1/4th of RX buffer to calculate amplitude/phase to reduce the "zeros" effect on those, but it's not a solution of the root cause.