This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Reading Inphase and Quadrature (IQ) Data from a Signal Analyzer over TCP/IP

This example shows how to acquire IQ Data from a signal analyzer over a TCP/IP interface.

Instrument Control Toolbox™ supports communication with instruments through interfaces and drivers.

For a complete list of supported hardware, visit the Instrument Control Toolbox product page at


This example acquires IQ Data from a Keysight Technologies® (formerly Agilent Technologies®) X-Series Signal Analyzer (N9020A, MXA Signal Analyzer) over a TCP/IP interface.


To run this example you need an X-Series Signal analyzer with an Ethernet (TCP/IP) connection. You can also execute this example with MATLAB on your X-Series analyzer, or on a PC on the same network as the X-Series Analyzer.

This example uses functions from the Instrument Control Toolbox and the DSP System Toolbox™.

Define Measurement Parameters

Define the parameters used to configure the instrument before you make the measurement. Based on the signal you are measuring, you may need to modify some of the following parameters.

% Specify the IP address of the signal analyzer
addressMXA = '';

Parameter Definitions

% Center frequency of the modulated waveform (Hz)
centerFrequency = 2.14e9;

% Bandwidth of the signal (Hz)
bandwidth = 25e6;

% Measurement time (s)
measureTime = 8e-3;

% Mechanical attenuation in the signal analyzer(dB)
mechAttenuation = 0;

% Start frequency for Spectrum Analyzer view
startFrequency = 2.11e9;

% Stop frequency for Spectrum Analyzer view
stopFrequency = 2.17e9;

% Resolution Bandwidth for Spectrum Analyzer view
resolutionBandwidth = 200e3;

% Video Bandwidth for Spectrum Analyzer view
videoBandwidth = 300;

Connect to the Instrument

Before you connect to the instrument:

  • Set up instrument connectivity using a TCP/IP connection.

  • Adjust the input buffer size so that it can hold the data the instrument returns.

  • Set the timeout to allow sufficient time for the measurement and transfer of data.

  • Connect to the instrument.

signalAnalyzerObject = tcpip(addressMXA, 5025);
signalAnalyzerObject.InputBufferSize = 30e6;
signalAnalyzerObject.Timeout = 20;

Query Instrument Identification Information

Reset the instrument to a known state using the appropriate SCPI command. Query the instrument identity to make sure we are connected to the right instrument.

fprintf(signalAnalyzerObject, '*RST');
instrumentInfo = query(signalAnalyzerObject, '*IDN?');
disp(['Instrument identification information: ' instrumentInfo]);
Instrument identification information: Agilent Technologies,N9020A,MY48011248,A.03.08

Set Up Instrument for an IQ Waveform Measurement

The X-Series signal and spectrum analyzers perform IQ measurements as well as spectrum measurements. In this example, you acquire the time domain IQ data, visualize it in MATLAB, and perform signal analysis on the acquired data. Use SCPI commands to configure the instrument to make the measurement and define the format of the data transfer once the measurement it made.

% Set up signal analyzer mode to Basic/IQ mode
fprintf(signalAnalyzerObject,':INSTrument:SELect BASIC');

% Set the center frequency
fprintf(signalAnalyzerObject,[':SENSe:FREQuency:CENTer ' num2str(centerFrequency)]);

% Set the resolution bandwidth
fprintf(signalAnalyzerObject,[':SENSe:WAVEform:BANDwidth:RESolution ' num2str(bandwidth)]);

% Turn off averaging
fprintf(signalAnalyzerObject,':SENSe:WAVeform:AVER OFF');

% set to take one single measurement once the trigger line goes high
fprintf(signalAnalyzerObject,':INIT:CONT OFF');

% Set the trigger to external source 1 with positive slope triggering
fprintf(signalAnalyzerObject,':TRIGger:WAVeform:SOURce IMMediate');
fprintf(signalAnalyzerObject,':TRIGger:LINE:SLOPe POSitive');

% Set the time for which measurement needs to be made
fprintf(signalAnalyzerObject,[':WAVeform:SWE:TIME '  num2str(measureTime)]);

% Turn off electrical attenuation.
fprintf(signalAnalyzerObject,':SENSe:POWer:RF:EATTenuation:STATe OFF');

% Set mechanical attenuation level
fprintf(signalAnalyzerObject,[':SENSe:POWer:RF:ATTenuation ' num2str(mechAttenuation)]);

% Turn IQ signal ranging to auto
fprintf(signalAnalyzerObject,':SENSe:VOLTage:IQ:RANGe:AUTO ON');

% Set the endianness of returned data
fprintf(signalAnalyzerObject,':FORMat:BORDer NORMal');

% Set the format of the returned data
fprintf(signalAnalyzerObject,':FORMat:DATA REAL,32');

Initiate Measurement

Trigger the instrument to make the measurement, wait for the measurement operation to be complete and read in the waveform. Before you process the data, separate the I & the Q components from the interleaved data returned by the instrument and create a complex vector in MATLAB.

% Trigger the instrument and initiate measurement

% wait till measure operation is complete
measureComplete = query(signalAnalyzerObject,'*OPC?');

% Read the IQ data
data = binblockread(signalAnalyzerObject,'float');

% Read the additional terminator character from the instrument

% Separate the data and build the complex IQ vector.
inphase = data(1:2:end);
quadrature = data(2:2:end);
IQData = inphase+1i*quadrature;

Display Information About the Measurement

The instrument provides information about the most recently acquired data. Capture this information and display it.

signalSpec = binblockread(signalAnalyzerObject,'float');
sampleRate = 1/signalSpec(1);
disp(['Sample Rate (Hz) = ' num2str(sampleRate)]);
disp(['Number of points read = ' num2str(signalSpec(4))]);
disp(['Max value of signal (dBm) = ' num2str(signalSpec(6))]);
disp(['Min value of signal (dBm) = ' num2str(signalSpec(7))]);
Sample Rate (Hz) = 44999999.8738
Number of points read = 360001
Max value of signal (dBm) = -64.8261
Min value of signal (dBm) = -130.6566

Plot the Acquired IQ Data

Plot the first 1000 points of acquired time domain data and annotate the figure.

hold on
legend('Inphase signal', 'Quadrature signal');
title('IQ Data for the first 1000 points of acquired signal')
xlabel('Sample number');

Plot the Spectrum View of the IQ Data

The spectrum view might have more information than the time domain view of the data. For example, you may use the spectrum view to identify the main frequency bands, the signal bandwidth, etc. You need the DSP System Toolbox to plot the spectrum view. You may get errors if the required functionality is not available.

% Create a periodogram spectrum with a Hamming window
hp = spectrum.periodogram('hamming');

% Create a power spectral density options object
hpopts = psdopts(hp,IQData);

% set the options for the periodogram
hpopts.Fs = sampleRate;
hpopts.SpectrumType' = 'twosided';
hpopts.Centerdc = true;

% calculate the PSD
hpsd = psd(hp,IQData,hpopts);

% plot the PSD of the acquired signal

Switch the Instrument Back to Spectrum Analyzer Mode

Switch the instrument to spectrum analyzer mode and compare the spectrum view generated in MATLAB with the view on the Signal Analyzer. Use additional SCPI commands are used to configure the instrument measurement and display settings.

% Switch back to the spectrum analyzer view
fprintf(signalAnalyzerObject,':INSTrument:SELect SA');

% Set mechanical attenuation level
fprintf(signalAnalyzerObject,[':SENSe:POWer:RF:ATTenuation ' num2str(mechAttenuation)]);

% Set the center frequency, RBW and VBW and trigger
fprintf(signalAnalyzerObject,[':SENSe:FREQuency:CENTer ' num2str(centerFrequency)]);
fprintf(signalAnalyzerObject,[':SENSe:FREQuency:STARt ' num2str(startFrequency)]);
fprintf(signalAnalyzerObject,[':SENSe:FREQuency:STOP ' num2str(stopFrequency)]);
fprintf(signalAnalyzerObject,[':SENSe:BANDwidth:RESolution ' num2str(resolutionBandwidth)]);
fprintf(signalAnalyzerObject,[':SENSe:BANDwidth:VIDeo ' num2str(videoBandwidth)]);

% Continuous measurement
fprintf(signalAnalyzerObject,':INIT:CONT ON');

% Trigger

Clean Up

% Close and delete instrument connections
clear signalAnalyzerObject