%% ASCII Data Read from 8753/8720 Network Analyzers
%
% This is the machine generated representation of an instrument control
% session. The instrument control session comprises all the steps you are
% likely to take when communicating with your instrument. These steps are:
%
% 1. Create an instrument object
% 2. Connect to the instrument
% 3. Configure properties
% 4. Write and read data
% 5. Disconnect from the instrument
%
% To run the instrument control session, type the name of the M-file,
% ag8753_get_data, at the MATLAB command prompt.
%
% The M-file, AG8753_GET_DATA.M must be on your MATLAB PATH. For additional information
% on setting your MATLAB PATH, type 'help addpath' at the MATLAB command
% prompt.
%
% Example:
% ag8753_get_data;
%
% See also SERIAL, GPIB, TCPIP, UDP, VISA.
%
%
% Creation time: 21-Nov-2006 09:57:54
%
% ojd - 1/12/2009
%
%% Create a VISA-GPIB object.
instrreset;
visa_addr='GPIB5::16::INSTR';
obj1 = instrfind('Type', 'visa', 'RsrcName', visa_addr, 'Tag', '');
% Create the VISA-GPIB object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
obj1 = visa('agilent', visa_addr);
else
fclose(obj1);
obj1 = obj1(1);
end
%max out buffer size for largest possible read of 1601 points
set(obj1,'InputBufferSize', 80050);
% Connect to instrument object, obj1.
fopen(obj1);
%% Communicating with instrument object, obj1.
data1 = query(obj1, 'OUTPIDEN');
fprintf(1, 'Connected to: %s\n', data1);
fwrite(obj1, 'FORM4; OPC?; SING');
opc_comp=fscanf(obj1);
%% Read data back from analyzer
fwrite(obj1, 'OUTPDATA');
data1=scanstr(obj1);
%Allocate space for data array
data=zeros(points,2);
%Convert output cell array into a standard two dimensional array
for i=1:1:points
data(i,1)=data1{(2*i)-1};
data(i,2)=data1{2*i};
end
%% Calculate Amplitude and Plot
%Allocate space for magnitude array
mag=zeros(points);
%Calculate Magnitude
for i=1:1:points
mag(i)=20*log10(sqrt(data(i,1)^2+data(i,2)^2));
end
plot(mag);
%% Clean-up
% Disconnect all objects.
fclose(obj1);
% Clean up all objects.
delete(obj1);