Agilent Signal Analyzer CXA N9000A

Hi,
I want to import data to MATLAB to make a logarithmic graph measurement on a spectrum analyzer Agilent N9000A. Windows XP is installed on the device just like MATLAB and Launch XSA (Signal Analyzer program). As Agilent’s recommendation, we have installed the driver Agilent X-Series. Matlab is now able to “communicate” with the CXA in one direction, we can now set parameters of measurements but we are not able to read “online” the values.
My purpose is very simple: I want to create two vectors of values that the instrument measures. One for a gain value in dB (y) and the other is the value of the frequency (x), then plot as semilogx (x, y).
I found some codes for the CXA in Agilent/MathWorks’website but it doesn’t work.
Find below my Matlab file (issues rise from the function “fprintf”, 2nd part of the code):
% Find a VISA-TCPIP object.
obj1 = instrfind('Type', 'visa-tcpip', 'RsrcName', 'TCPIP0::localhost::inst0::INSTR', 'Tag', '');
% Create the VISA-TCPIP object if it does not exist % otherwise use the object that was found.
if isempty(obj1)
obj1 = visa('AGILENT', 'TCPIP0::localhost::inst0::INSTR');
else
fclose(obj1);
obj1 = obj1(1)
end
% Configure instrument object, obj1
set(obj1, 'InputBufferSize', 20000000);
% Configure instrument object, obj1
set(obj1, 'OutputBufferSize', 512);
Create a VISA-TCPIP object.
interfaceObj = instrfind('Type', 'visa-tcpip', 'RsrcName', 'TCPIP0::localhost::inst0::INSTR', 'Tag', '');
% Create the VISA-TCPIP object if it does not exist % otherwise use the object that was found.
if isempty(interfaceObj)
interfaceObj = visa('AGILENT', 'TCPIP0::localhost::inst0::INSTR');
else
fclose(interfaceObj);
interfaceObj = interfaceObj(1);
end
% Create a device object.
deviceObj = icdevice('Agilent_SA_Driver2.mdd', interfaceObj);
% Connect device object to hardware.
connect(deviceObj);
FreqStar = 100E3;
FreqStop = 10E6;
% Configure property value(s).
set(deviceObj, 'SAFreqStart', FreqStar); set(deviceObj, 'SAFreqStop', FreqStop);
%IQDATA = get(deviceObj,'WavCurrentCapture');
%SampleRate = get (deviceObj,'WavSampleRate'); % % Set the reference level to +10 dBm % fprintf(mxa,':DISP:WIND:TRAC:Y:RLEV 10');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%% IT DID'NT WORK FROM HERE %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set the data trace format to REAL, 32 bits
fprintf(obj1,':FORM:DATA REAL,32');
% Get the nr of trace points
nr_points = str2double(query(obj1,':SWE:POIN?'));
% Get the trace data
fprintf(obj1,':TRAC? TRACE1');
data = binblockread(obj1,'float32');
fscanf(obj1); %removes the terminator character
% data = get(deviceObj,'WavLastCapture'); % binblockwrite(obj1,data,'uint8',':MMEM:DATA "D:\STATE000.STA",'); % create and bring to front figure number 1
figure
Freq = linspace(FreqStar,FreqStop,nr_points);
% Plot trace data vs frequency
semilogx(Freq,data)
xlim([FreqStar FreqStop])
title('Result trace')
xlabel('Frequency [Hz]')
ylabel('Amplitude [dB]')
grid on
Best regards and thank you for your help
Florian

 채택된 답변

Vinod
Vinod 2012년 8월 9일

0 개 추천

You might also want to refer to the instrument's programming manual for the SCPI commands necessary to control the instrument for the specific measurements you are interested in.

추가 답변 (1개)

Florian
Florian 2012년 8월 9일

0 개 추천

Thank you Mr. Cherian for your answer.
I already resolve the problem with the function:
swapbytes (single (data))
The data which was returned by the instrument were singles in big-endian format whereas MATLAB (or my instrument driver) tried interpreting it as little-endian doubles.
Best regards
Florian

카테고리

도움말 센터File Exchange에서 Digital Input and Output에 대해 자세히 알아보기

질문:

2012년 7월 20일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by