AnsweredAssumed Answered

E4407B with matlab

Question asked by hfler on Aug 27, 2013
Latest reply on Sep 20, 2013 by tabbott
Hi!

I need the Matlab code to get the plot of attenuation agains Frequency. I wrote one but  i did not get the true plot. The spectrum analyzer is connected with GPiB. I hope u could help.


set(mxa,’InputBufferSize’,4005);
% instrument response timeout
set(mxa,’Timeout’,5);
fopen(mxa);
% Set the data trace format to REAL, 32 bits
fprintf(mxa,’:FORM:DATA REAL,32’);
% Get the nr of trace points
nr_points = str2double(query(mxa,’:SWE:POIN?’));
% Get the reference level
ref_lev = str2num(query(mxa,’:DISP:WIND:TRAC:Y:RLEV?’));
% Get the trace data
fprintf(mxa,’:INIT:IMM;*WAI’); % start a sweep and
%wait until it completes
fprintf(mxa,’:TRAC? TRACE1’);
data = binblockread(mxa,’fl oat32’); % get the trace data
fscanf(mxa); %removes the terminator character
% create and bring to front fi gure number 1
fi gure(1)
% Plot trace data vs sweep point index
plot(1:nr_points,data)
% Adjust the x limits to the nr of points
% and the y limits for 100 dB of dynamic range
xlim([1 nr_points])
ylim([ref_lev-100 ref_lev])
% activate the grid lines
grid on
title(‘Swept SA trace’)
xlabel(‘Point index’)
ylabel(‘Amplitude (dBm)’)
% Disconnect an clean up
fclose(mxa);
delete(mxa);
clear;  

Outcomes