AnsweredAssumed Answered

Matlab LibIIO AD9361 channel size and sampling frequency

Question asked by ddk on Nov 28, 2017
Latest reply on Dec 18, 2017 by ddk

I'm Using a #ZC702 dev board with #FMCOMMS3-EBZ devices ( #AD9361)
I'm attempting to build a channel occupancy scanner and I'm having trouble correlating the libiio buffered transfers with the sampling frequency to capture "full RF channels"#

 

in short I'm trying to do an FFT of an entire "channel" ( channel is <half of my Fs ), so the following example the channel is 8 MHz wide (analog filter set to be 10 MHz wide )

 

How does the number of iterations when calling "output = stepImpl(s, input);" relate to "s.out_ch_size" and Fs  if I want to capture all the data needed to inspect the spectral data for the Rf channel ?

 

in this following example ( from , Fs is set to 30.72 MHz, the iio buffer size is set to 8192 samples and the for loop iterates 5 times ( modified from the   fmcomms2_3_data_stream / ad9361_matlab.m )

 

do I need to concatenate the buffer transfers into a single larger array similar to Discontinuities in between data transfers and then commit FFT on that data ?

 

Example code :

 

%%iio device settings
s = iio_sys_obj_matlab;         % Constructor
s.ip_address = '10.0.0.2';       % iio device IP addr
s.dev_name = 'ad9361_rx1'; % cfg file reference
s.in_ch_no = 0;                      % data going INTO  SDR
s.out_ch_no = 2;                     % data coming OUT of SDR
s.in_ch_size = 8192;               % iio Transmit buffer size (MATLAB-> iio->SDR->air )
s.out_ch_size = 8192;              % iio Recieve Buffer transfer size ( air->SDR->iio->MATLAB )

 

s = s.setupImpl();

 

 %%FFT parameters

Flo = 2.4e9;                  % channel "location"
Fs = 30.72e6;               % Sampling Freq
Ts = 1/Fs;                       % Sampling Interval (sec)
Fn = Fs/2;                       % Nyquist Frequency (Hz) ( does this apply when using direct IQ ? )

 

L = s.out_ch_size;              % Length of signal buffer ( should this not be Fs if we need fft of the whole "Rf channel"? )
t = 1/Fs:1/Fs:s.out_ch_size/Fs; % Time vector ( begin : dx : end )

 

%% SDR channel and sampling config
input{s.in_ch_no+1} = Flo;
input{s.in_ch_no+2} = Fs;       % FMCOMMS3 ADC sampling freq
input{s.in_ch_no+3} = 10.0e6;   % RX1 input filter BW
% (RX  I data )
input{s.in_ch_no+4} = 'manual'; % Gain mode
input{s.in_ch_no+5} = 0;        % gain setting
% (RX  Q data )
input{s.in_ch_no+6} = 'manual'; % Gain mode
input{s.in_ch_no+7} = 0;        % gain setting

 

 %% Setup SDR recieve buffer arrays

output = cell(1, s.out_ch_no + length(s.iio_dev_cfg.mon_ch));

outputComplex = cell(1,  length(s.iio_dev_cfg.mon_ch));

 

%% Capture data
for i = 1:5
    % get output form device ( also does tx)
output = stepImpl(s, input);

 

I = output{1};
Q = output{2};

 

%get RSSI
rssi1 = output{s.getOutChannel('RX1_RSSI')}; % RX1 RSSI ( I )
rssi2 = output{s.getOutChannel('RX2_RSSI')}; % RX1 RSSI ( Q )

 

outputComplex = complex(I,Q);
% outputComplex = I+1i*Q;
end

 

%% Release system object
s.releaseImpl();

 


%% Compute the Fourier transform of the signal.
outFFT = fft(outputComplex);
% Compute the two-sided spectrum P2. Then compute the single-sided spectrum
%P1 based on P2 and the even-valued signal length L ( this should by FS, but iio buffers are much smaller )
P2 = abs(outFFT/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
% calculate time intervals for plot
f = (Fs*(0:(L/2))/L);

 


%% Plot Data
figure % new figure
ax1 = subplot(3,1,1); % top subplot
ax2 = subplot(3,1,2); % mid subplot
ax3 = subplot(3,1,3); % bottom subplot

 

plot(ax1,output{1});
title(ax1,'I');
xlabel('Sample');
ylabel('Amplitude');

 

plot(ax2,output{2});
title(ax2,'Q');
xlabel('Sample');
ylabel('Amplitude');

 

plot(ax3,P1);
title(ax3,'Single-Sided Amplitude Spectrum');
xlabel('f (Hz)')
ylabel('|P1(f)|')


The aim is to eventually do this in the PL of the ZC702. and have run into issues in Simulink. ( possibly for a different thread/topic/question regarding libiio and system objects in iterators in simulink)

 

it seems to work for "full spectrum captures" in simulink, but the Matlab system object cannot be used ( system hangs) when placed in a for iterator ( so I can iterate through channels ) - I think it might be due to the repeated call to " s = s.setupImpl();" from within the for-iterator.

 

-Daniel

Outcomes