Trying to model RF part of board

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

Trying to model RF part of board

Post by fdavies »

I am continuing to work on using the bladeRF as part of a vector network analyzer (VNA) or at least a scalar network analyzer.
I have a good Octave script which uses command line calls of bladeRF-cli to gather a spectrum in 6 MHz chunks.
I have made several runs with cables connecting input and output. The following shows the results for a 1120 mm long 50 ohm coax cable.
6.png
IMG_3201_small.JPG
The spacing (frequency difference between crests) clearly corresponds to the length of the cable. However, the ripple itself is something like 15 dB high. I am trying to understand this by building a model in qucs.

Question:
1. Do you have a Spice or qucs model of the input and output of the bladeRF?
2. Do you know the parameters (PCB material (FR-4?), width of trace, thickness of PCB layer between trace and ground plane) that would let me make a model of the input and output? I have the schematic of the board and data sheets of the relevant components.
3. Do you have any thoughts about reducing this ripple?

Thanks,

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

Re: Trying to model RF part of board

Post by bpadalino »

For the answers to the questions:

1) No Spice models, sorry.
2) It's FR4 and the trace impedance is matched to be as close to 50 ohms as possible.
3) I am not 100% sure what you're measuring there so I am not sure what may be happening? Can you explain what you do with each 6MHz swath? Are you transmitting a PN/CAZAC sequence and looking at the impulse response in that 6MHz span then potting the magnitude?

15dB does sound like quite a bit of variation.
fdavies
Posts: 15
Joined: Wed Jul 15, 2015 6:52 pm

Re: Trying to model RF part of board

Post by fdavies »

Thanks for the reply.
I am using the following Octave script. It loops through a frequency range. At each frequency it sets the transmit frequency to the desired frequency and the receive frequency to about 6 MHz higher. It then calls a bladeRF-cli script that transmits a frequency sweep of a little more than 6 MHz while receiving. It transmits 3 times because that means that I do not have to synchronize the receive with the transmit very well. The received data has an FFT run on it and is trimmed down. This is then appended to the previous results to give a complete spectrum.

Code: Select all

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

GUARD_BAND= 0.5e6;  % separate the frequency sweep zone from the DC spikes
SAMPLE_RATE = 24e6;
NUM_SAMPLES = 131072;  % 
NUM_SECONDS = NUM_SAMPLES/SAMPLE_RATE;

SCAN_WIDTH = (SAMPLE_RATE/4-GUARD_BAND*2);

SCAN_START =300e6; %300
SCAN_STOP = 3775e6;  %3775

freq_list = SCAN_START:SCAN_WIDTH:SCAN_STOP;

START_FREQ_RAD = (GUARD_BAND/2) * 2 * pi;  % it will be a complex frequency
STOP_FREQ_RAD = (SAMPLE_RATE/4-(GUARD_BAND/2)) * 2 * pi;

RX_TX_DELTA = SAMPLE_RATE/4;  % to prevent rx PLA and tx PLA mutual interference (pos for rx>tx)

DELTA= (1/2)*(STOP_FREQ_RAD - START_FREQ_RAD)/NUM_SECONDS;
t = [ 0 : (1/SAMPLE_RATE) : ((NUM_SECONDS) - 1/SAMPLE_RATE) ];
tx_signal = (0.8+(0.075/NUM_SECONDS)*t) .* 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(["cal lms"]);
  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'"]); % 0 3 6
  system(["bladeRF-cli -e 'set rxvga1 5'"]); % [5, 30]
  system(["bladeRF-cli -e 'set rxvga2 0'"]); % [0, 30]
  system(["bladeRF-cli -e 'set txvga1 -14'"]); %  [-35, -4]
  system(["bladeRF-cli -e 'set txvga2 10'"]); % [0, 25]
  system(["bladeRF-cli -e 'tx config delay=0'"]); %

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

% so, it works by transmitting the sweep signal 3 times while activating 
% the receive.  This is necessary because I do not know how to synchonize
% the transmit and receive well

% so, transmit a frequency sweep from tx_freq+START_FREQ_RAD to tx_freq+STOP_FREQ_RAD
% note that this includes guard bands so it is wider than SCAN_WIDTH
% the part of the frequency sweep that will actually end up in the result is
%    tx_freq+GUARD_BAND to tx_freq+GUARD_BAND+SCAN_WIDTH
% receive it with a rx base frequency that is offset from the tx base frequency

%%%   now for the loop
for fr=freq_list
  % set the transmit and receive frequencies
  tx_freq = fr - GUARD_BAND;
  rx_freq = tx_freq+RX_TX_DELTA;
  system(["bladeRF-cli -e 'set frequency rx ",num2str(rx_freq),"'"]);
  system(["bladeRF-cli -e 'set frequency tx ",num2str(tx_freq),"'"]);
  system("bladeRF-cli -s script_H_1.txt"); % see below for contents of script_H_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);
  % the spectrum will go from -1/SAMPLE_RATE to 1/SAMPLE_RATE in frequency
  spectrum=20*log10(abs(fftshift(fft(rx_signal)))/NUM_SAMPLES);
  trim_start = floor(NUM_SAMPLES/4+NUM_SAMPLES*(GUARD_BAND/SAMPLE_RATE));
  trim_stop = floor(NUM_SAMPLES/2-NUM_SAMPLES*(GUARD_BAND/SAMPLE_RATE));
  trim_width = trim_stop-trim_start+1;
  trimmed_spectrum=spectrum(trim_start:trim_stop);
  result=[result trimmed_spectrum]; % add a chunk to the result
  freq_result = [freq_result fr:SCAN_WIDTH/trim_width:fr+SCAN_WIDTH-(SCAN_WIDTH/trim_width)];
endfor

clf;
rx1=real(rx_signal);
h4=plot(freq_result,result);  %  here is where we see the result
axis([freq_result(1) freq_result(end) -50 30]);
h6=title('Spectrum assembled from pieces');grid on
h7=xlabel('Frequency');
h8=ylabel('dB');
grid on;
set(gca(),'xtick',min(freq_list):1e8:max(freq_list));
%set(gca(),'xtick',min(freq_list):1e6:max);
%set(gca(),'ytick',-30:5:30);
%saveas(h1,"t.png",'png');

% ***************************************
%  this is the script file used by the above
%
% tx config delay=0
% tx config file=/media/ramdisk/tx_waveform.sc16q11 format=bin
% rx config file=/media/ramdisk/rx_sample n=131072
% tx config repeat=3
% tx start 
% rx start
% tx wait
% rx wait
%

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=131072
tx config repeat=3
tx start 
rx start
tx wait
rx wait
This is not very fast, but it works pretty well, I think.

The issue comes when I connect the TX to the RX with various length cables. After adjusting the transmit gains so that there in not saturation, I see ripples like in the first message. The longer the cable, the closer the ripple crests are to each other, which makes sense.. I have made a very primitive model with QUCS which shows similar ripples.

I will make a second post with more info tonight.

Thanks,

Frank Davies
281 483 9033
fdavies
Posts: 15
Joined: Wed Jul 15, 2015 6:52 pm

Re: Trying to model RF part of board

Post by fdavies »

Here are what I got for two shorter cables:

218 mm cable
5.png
270 mm cable
3.png
The longest cable (first post) makes it easier to separate the effect of the cable.

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

Re: Trying to model RF part of board

Post by bpadalino »

Thanks for the update.

I still don't quite understand the swings unless we really have a crazy mismatch somewhere in the system. Could you add a 3dB pad, rerun your measurements and see if the peaks are still there?

I actually suspect your measurement methodology may be problematic? Could you also try just outputting a single CW instead of the whole chirp to get your magnitude information for just a single frequency for every 6MHz and just connect those dots?

I know it's a lot to ask, but starting simpler and getting more complex might be a good way to rule out what may be happening.
fdavies
Posts: 15
Joined: Wed Jul 15, 2015 6:52 pm

Re: Trying to model RF part of board

Post by fdavies »

Thanks for the suggestions. I will try them over the weekend.

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

Re: Trying to model RF part of board

Post by fdavies »

Here are the results with attenuators. The blue is with no attenuators, just loop back through a long RG58 cable. The red is the loopback cable in series with a 3dB attenuator (pad) on RX. The remaining color (cyan?) is the loopback cable with a 20 dB attenuator on TX and a 3dB attenuator on RX. I wish that I had two 3dB attenuators, but I do not yet.
long_cable_with_attenuators_annotated.png
So, as you said, the problem is reflections. I have a solution that will be adequate for my purposes (investigating resonant cavities), particularly when I have purchased more attenuators.

Thanks,

Frank Davies
Post Reply