Funny envelope of frequency sweep while tx and rx

Having issues with the site, hardware, source code, or any other issues?
Post Reply
fdavies
Posts: 15
Joined: Wed Jul 15, 2015 6:52 pm

Funny envelope of frequency sweep while tx and rx

Post by fdavies »

I am trying to make an approximation to a VNA.

To this end, I am transmitting and receiving at the same time. I am working at 2e6 samples per second.
In order to do this, I have an octave script that makes a frequency sweep file (complex frequency).
It also sets up the bladeRF, then calls a script that starts receiving, then starts transmitting. I set the board to receive for twice as many samples as to transmit, so that I get the whole transmission.
The problem is that the received signal has a funny looking envelope that is not flat. In addition, it is randomly one of two non-flat envelopes. I have attached screen shots of Octave plots of the real parts of the time waveforms (not spectra).
rx_signal_2.png
rx_signal_1.png
I am not using the loop-back mode, but am connecting rx to tx through a home-made attenuator.

Here is the Octave file:

Code: Select all

%  
% based on a file from https://github.com/Nuand/bladeRF/wiki/bladeRF-CLI-Tips-and-Tricks
%  modified
%

SAMPLE_RATE = 2e6;
NUM_SAMPLES = 131072;  % for tx, not rx
NUM_SECONDS = NUM_SAMPLES/SAMPLE_RATE;

START_FREQ_RAD = -0.9e6 * 2 * pi;  % it will be a complex frequency
STOP_FREQ_RAD = 0.9e6 * 2 * pi;

f_axis = linspace(-0.5 * SAMPLE_RATE, 0.5 * SAMPLE_RATE, NUM_SAMPLES);

DELTA= (1/2)*(STOP_FREQ_RAD - START_FREQ_RAD)/NUM_SECONDS;
t = [ 0 : (1/SAMPLE_RATE) : ((NUM_SECONDS) - 1/SAMPLE_RATE) ];
tx_signal = 0.90 * exp(1j .* (START_FREQ_RAD+DELTA.*t) .* t);

save_sc16q11('/media/ramdisk/tx_waveform.sc16q11', tx_signal);

%  set up the bladeRF with a bunch of system command line calls
  system(["bladeRF-cli -e 'set samplerate rx ",num2str(SAMPLE_RATE),"'"]);
  system(["bladeRF-cli -e 'set bandwidth rx ",num2str(SAMPLE_RATE),"'"]);
  system(["bladeRF-cli -e 'set bandwidth tx ",num2str(SAMPLE_RATE),"'"]);
  system(["bladeRF-cli -e 'set samplerate tx ",num2str(SAMPLE_RATE),"'"]);
  system(["bladeRF-cli -e 'set lnagain 0'"]);
  system(["bladeRF-cli -e 'set rxvga1 30'"]);
  system(["bladeRF-cli -e 'set rxvga2 30'"]);
  system(["bladeRF-cli -e 'set txvga1 -4'"]);
  system(["bladeRF-cli -e 'set txvga2 25'"]);
  system(["bladeRF-cli -e 'tx config delay=0'"]);

result=[]; % for when I do many in a row
freq_result=[];

freq_list=[1000e6]; % just one for now.

%%%   now for the loop
for f=freq_list
  % set the transmit and receive frequencies
  system(["bladeRF-cli -e 'set frequency rx ",num2str(f),"'"]);
  system(["bladeRF-cli -e 'set frequency tx ",num2str(f),"'"]);
  system("bladeRF-cli -s script_D_1.txt"); % see below for contents of script_D_1.txt
  f = fopen("/media/ramdisk/rx_sample", "r", "ieee-le");
  samples = fread(f, Inf, "int16");
  fclose(f);
  samples_i = samples(1:2:end, :);
  samples_q = samples(2:2:end, :);
  rx_signal = samples_i + j * samples_q;
  spectrum=20*log10(abs(fftshift(fft(rx_signal)))/NUM_SAMPLES);
  %freq_result=[freq_result f_axis(s1:s2)];
  result=[result spectrum'];
  %pause(10);
endfor

plot(real(rx_signal)); % not the spectrum

% script file script_D_1.txt is as follows:
%
% tx config delay=0
% tx config file=/media/ramdisk/tx_waveform.sc16q11 format=bin
% rx config file=/media/ramdisk/rx_sample n=262144
% tx config repeat=1
% rx start 
% tx start
% tx wait
% rx wait
%
Here is the script for bladeRF-cli:

Code: Select all

tx config delay=0
tx config file=/media/ramdisk/tx_waveform.sc16q11 format=bin
rx config file=/media/ramdisk/rx_sample n=262144
tx config repeat=1
rx start 
tx start
tx wait
rx wait
What am I doing wrong?

I do think that I have the latest version of everything, as shown below:
bladeRF> info

Serial #: ffc7ad36f80a326e49f7921529a3669a
VCTCXO DAC calibration: 0xa104
FPGA size: 40 KLE
FPGA loaded: yes
USB bus: 4
USB address: 2
USB speed: SuperSpeed
Backend: libusb
Instance: 0

bladeRF> version

bladeRF-cli version: 1.2.0-git-067bd41
libbladeRF version: 1.4.0-git-067bd41

Firmware version: 1.8.0
FPGA version: 0.3.3
bpadalino
Posts: 303
Joined: Mon Mar 04, 2013 4:53 pm

Re: Funny envelope of frequency sweep while tx and rx

Post by bpadalino »

Looks like you're sweeping from -0.9MHz to 0.9MHz with a 2MHz sample rate?

There is no sin(x)/x correction in the LMS on the output of the DAC, so that might explain the envelope being small then rising up then coming down. As you approach Fs/2, the amplitude of the signal will distort by a sin(x)/x rolloff.

Can you try oversampling your data by a factor of 2 - using a 4MHz sample rate, but only going from -0.9MHz to 0.9MHz, or using the 2MHz sample rate and only going -0.5MHz to 0.5MHz? That should be an interesting experiment to run.

I wonder if some weird harmonic content is coming in through the reconstruction filter and causing some interesting effects to be seen.

Brian
fdavies
Posts: 15
Joined: Wed Jul 15, 2015 6:52 pm

Re: Funny envelope of frequency sweep while tx and rx

Post by fdavies »

I think I understand what you are saying (ghostly images of convolution and sync functions are flitting through my head from almost 30 years ago). Doing a frequency sweep of -0.5MHz to 0.5MHz with a 2 MHz sample rate makes the problem mostly go away, certainly. It is not clear to me why it would have two distinct different ways of showing this issue, though.
rx_signal_3.png
Anyway, getting a 1 MHz chunk of spectrum for a 2 MHz sample rate is not so bad, I guess. I will proceed with this workaround.

Thanks,

fdavies
bpadalino
Posts: 303
Joined: Mon Mar 04, 2013 4:53 pm

Re: Funny envelope of frequency sweep while tx and rx

Post by bpadalino »

I agree, I am not 100% sure why it would manifest itself in 2 different ways.

Glad you were able to get it to mostly go away.

Let us know if you're able to get your project up and working! Are you blogging anywhere about your experiences?

Brian
Post Reply