Code covered by the BSD License  

Highlights from
Agilent Spectrum Analyzer Seminar Examples

image thumbnail
from Agilent Spectrum Analyzer Seminar Examples by Richard Overdorf
Agilent MXA, PSA Seminar Examples

example6
function example6
% MATLAB/MXA example 6
% Getting and plotting trace data
% Continuous aquisition	with timer

% Version: 1.0
% Date: Sep 11, 2006  
% 2006 Agilent Technologies, Inc.

oldobjs=instrfind;
if ~isempty(oldobjs)
disp('Cleaning up ...')
delete(oldobjs);
clear oldobjs;
end

% Initial setup
%mxa_ip = '141.121.95.143';...use localhost for inside the instrument
mxa_ip = 'localhost';
mxa_port = 5025;

% MXA Interface creation and connection opening
%mxa_if = tcpip(mxa_ip,mxa_port);
%mxa = icdevice('IQ_Analyzer_v14.mdd', mxa_if);

mxa=tcpip(mxa_ip, mxa_port);
set(mxa,'InputBufferSize',30000);
set(mxa,'Timeout',5);
fopen(mxa);

% Set the data trace format to REAL, 32 bits
fprintf(mxa,':FORM:BORD NORMAL');
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?'));
% Put the instrument in continuos mode
fprintf(mxa,':INIT:CONT ON');

% create and bring to front figure number 1
figure(1)
ph = plot(1:nr_points,ref_lev*ones(1,nr_points));
% 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])
grid on

th =timer('timerfcn',@update_plot,...
          'ExecutionMode','FixedRate',...
          'Period',0.1);
 
start(th)
pause(5)
stop(th)



% Disconnect an clean up
fclose(mxa);
delete(mxa);
clear mxa;

    function update_plot(varargin)
        % Get the trace data
        fprintf(mxa,'TRAC? TRACE1');

        data = binblockread(mxa,'float32');
        fscanf(mxa); %removes the terminator character

        % Plot trace data vs sweep point index
        set(ph,'Ydata',data);
        drawnow
        

    end

end

Contact us at files@mathworks.com