Documentos de Académico
Documentos de Profesional
Documentos de Cultura
The R&S MATLAB® Toolkit for Signal Generators and Power Sensors
provides routines for remote controlling these instruments. Additional
MATLAB® scripts turn I/Q vectors into the Rohde & Schwarz waveform
file format for use with an ARB. This application note describes the
installation and use of the R&S MATLAB® Toolkit on Microsoft Widows
and Linux based systems.
Application Note
T. Roeder, C. Troester
02/04/09
Table of Contents
1 Notices........................................................................................4
2 Overview.....................................................................................5
3 Features......................................................................................5
4 System Requirements...............................................................6
4.1 Hardware........................................................................................................6
4.2 Software.........................................................................................................6
5 Release Notes............................................................................7
6 Windows XP Installation...........................................................8
6.1 Unpacking The Files.....................................................................................8
6.2 Setting The Path In MATLAB........................................................................8
7 Linux Installation.....................................................................10
7.1 Prerequisites................................................................................................10
7.2 Unpacking The Files...................................................................................10
7.3 VISA Installation..........................................................................................10
7.4 Compiling The Gateway Driver..................................................................11
7.5 USB Support................................................................................................11
13 ADS Support.............................................................................26
13.1 Installation...................................................................................................26
13.2 Usage...........................................................................................................26
1 Notices
The following abbreviations are used throughout the application.
● The MATLAB® Toolkit for Signal Generators and Power Sensors is referred to as
MATLAB Toolkit or toolkit.
● The R&S® SMU200A Vector Signal Generator is referred to as SMU.
● The R&S® SMJ100A Vector Signal Generator is referred to as SMJ.
● The R&S® SMATE200A Vector Signal Generator is referred to as SMATE.
● The R&S® SMBV100A Vector Signal Generator is referred to as SMBV.
● The R&S® AFQ100A I/Q Modulation Generator is referred to as AFQ.
● The R&S® AFQ100B UWB Signal and I/Q Modulation Generator is referred to as
AFQ.
● The R&S® AMU200A Baseband Signal Generator and Fading Simulator is referred
to as AMU.
Microsoft®, Windows®, MS Windows®, Windows NT®, and MS-DOS® are U.S. registered
trademarks of Microsoft Corporation.
Agilent® and Agilent® EEsof ADS are registered trademarks of Agilent Technologies.
Rohde & Schwarz® is a registered trademark of Rohde & Schwarz GmbH & Co. KG.
2 Overview
MATLAB is widely used for the simulation of communication systems as well as for the
creation or analysis of custom signals. The MATLAB Toolkit provides functions that link
the Rohde & Schwarz instruments to the MATLAB environment. For this purpose the
toolkit contains scripts for the most common tasks, such as instrument remote control
and data transfer. A set of example scripts demonstrate the use of the toolkit functions
in various applications. The toolkit supports the instrument remote control via GPIB
hardware, raw TCP/IP socket connections, or the VISA (Virtual Instrument Software
Architecture) interface.
3 Features
The MATLAB Toolkit provides the following functionality.
4 System Requirements
4.1 Hardware
● The MATLAB requirements (CPU, memory, hard drive)
● For the instrument remote control (depending on instrument)
– 100MBit LAN
– GPIB hardware
– USB interface
● For the NRP-Z Power Sensor remote control
– USB interface
– Either R&S NRP-Z3 or R&S NRP-Z4 adapter
4.2 Software
The MATLAB Toolkit can be used on Microsoft Windows XP or Linux operating
systems. The following configuration was tested by Rohde & Schwarz.
5 Release Notes
V 1.0 - First release
6 Windows XP Installation
‘Rs_Matlab_Toolkit_<version number>.zip
C:\Program Files\MATLAB\R2007a\toolbox\RsMatlabToolkit
The contents of the archive should now be unpacked into this directory.
Note: When using MATLAB 7.0 (R14) it is required to remove unused instrument
drivers. This is a confirmed bug in MATLAB 7.0 (R14) in the way that MATLAB
interfaces with GPIB cards.
\toolbox\instrument\instrumentadaptors\win32
in the MATLAB directory, create a new directory called backup and move every dll
except mwnigpib.dll and mwnivisa.dll to the backup directory.
www.mathworks.com/support/solutions/data/1-PJ6VF.html
7 Linux Installation
At the time of writing there is no direct VISA support available from within MATLAB. To
overcome this issue the MATLAB Toolkit provides a C based gateway routine that acts
as the link between MATLAB and VISA or GPIB. The gateway routine is available as
source code and needs to be compiled on the target system using the MATLAB ‘mex’
command.
7.1 Prerequisites
● Linux distribution with kernel sources and symbols installed
● C compiler such as gcc
Extract all Linux related files into a path in your MATLAB toolbox directory.
# md /opt/matlab2006/toolbox/Rs_Matlab_Toolkit
After the files are unpacked follow the Step ‘Set the path to the toolkit in MATLAB’ from
the Windows installation procedure.
# cd /usr/src/linux
# make cloneconfig
# make prepare
# mkdir /tmp/iso
# mount –t iso9660 –o loop,ro <imagefile> /tmp/iso
# cd /mnt/iso
Run the National Instruments installer and make sure to add the ‘development’ option.
# ./INSTALL
You should now have a working VISA installation. Verify your installation by invoking
the NIvisaic or visaconf tools.
# NIvisaic
# visaconf
The default path is /usr/local/vxipnp/linux/lib. Note this path and start MATLAB. Next,
change to the installation directory of the MATLAB Toolkit and execute the mex
command below to compile the gateway.
mex –L /usr/local/vxipnp/linux/lib
–l visa rs_LinuxVisaDriver.c
If no error messages appear you are ready to use the example files from the
MATLAB Toolkit.
By default only the root user is allowed for raw access to USB devices. In order to allow
access to normal users National Instruments provides a script that configures your
system accordingly. Execute this script as root user.
# /usr/local/vxipnp/linux/NIvisa/USB/
AddUsbRawPermissions.sh
Enter the vendor ID 0x0AAD for Rohde & Schwarz and the product of your instrument.
A list of all product IDs can be found in the next chapter.
For all Rohde & Schwarz devices the vendor ID is 0x0AAD. The product ID depends on
the instrument and can be taken from the list below.
NRP-Z11 0x0C
NRP-Z21 0x03
NRP-Z22 0x13
NRP-Z23 0x14
NRP-Z24 0x15
NRP-Z31 0x2C
NRP-Z51 0x16
NRP-Z52 0x17
NRP-Z55 0x18
NRP-Z81 0x23
NRP-Z91 0x21
NRP-Z27 0x2F
NRP-Z37 0x2D
The list represents all R&S Signal Generators and R&S NRP-Z Power Sensors that
support USB remote control at the time of writing.
9.1 rs_connect ()
The function rs_connect() sets up the instrument connection and tests the link. It
returns a handle to the remote controlled instrument. The connection can be made
using the GPIB or VISA interface as well as via a raw TCP/IP socket connection.
GPIB parameters
<board number> GPIB board number (usually 0)
<primary address> GPIB bus address of the instrument
<secondary address> The secondary GPIB bus address
of the instrument (optional)
VISA parameters
<VISA resource string> The VISA resource string describes the
device as well as the interface type.
TCP/IP parameters
<hostname> The instrument host name used in the network
Return values
<status > 1 if successful
<object > The handle to the instrument
The GPIB and VISA functions require an identifier for the installed hard- or software
interface. The function call for opening device number 28 connected to the first
National Instruments GPIB card is
VISA offers more flexibility over direct GPIB connections as it allows the use of different
interface types. Please consult your Rohde & Schwarz instrument manual or data sheet
for details about which remote control interface is supported by your instrument.
Please see the documentation of your VISA installation for details about the VISA
resource strings.
Please Note: LAN based remote control requires that the instrument firewall is
disabled. This, for example, applies to the Microsoft Windows based instruments SMU,
SMJ, and SMATE. The Linux based instruments, such as the SMBV do not have a
firewall.
9.2 rs_send_command ()
The function rs_send_command() sends a single SCPI command to a previously
connected instrument.
Parameters
<object> The instrument object returned by rs_connect()
<command> SCPI command, e.g. ‘FREQ 1.2GHz’
Return value
<status> 1 if successful
Example code
[err, instrObj] = rs_connect (‘gpib’, ‘ni’, 0, 28);
err = rs_send_command (instrObj, '*RST');
9.3 rs_send_query ()
The function rs_send_query() works similar to rs_send_command() with the exception
that an answer from the instrument is expected after the command has been sent.
Parameters
<object> The instrument object returned by rs_connect()
<command> SCPI command, e.g. ‘*IDN?’
Return values
<status> 1 if successful
<answer> Contains the answer from the instrument
Example code
[err, instrObj] = rs_connect (‘gpib’, ‘ni’, 0, 28);
[err, answer] = rs_send_query (instrObj, '*IDN?');
9.4 rs_batch_interpret ()
This function executes a series of SCPI commands or queries from a text file.
Parameters
<object> The instrument object returned by rs_connect()
<batch-file> Path and name of the batch-file
Return values
<status> 1 if successful
<answer> Contains the queries results in a structure
answer(x).text, where x is a consecutive number
of the queries, starting with the index one.
The highest number is the total number of queries.
Example code
[err, answer] = rs_batch_interpret (instrObj, ‘scpi.txt');
9.5 rs_generate_wave ()
This function builds a R&S waveform file from MATLAB I/Q data. In addition, it sends
the generated file to the instrument and starts the ARB in path A or B.
Parameters
<object > The instrument object returned by rs_connect()
If this number is set to 0 the waveform is only
stored locally and not sent to the instrument.
<struct> I/Q data and waveform parameters
<playback> 0 = ARB is not started after transfer
1 = waveform is activated in path A
2 = waveform is activated in path B
<save_local> 0 = waveform is not stored on local PC
1 = waveform is stored on local PC (current directory)
Return value
<status> 1 if successful
Marker lists can be used for synchronization of other instruments or as indication for
certain parts of a waveform. For more information please see the user manual or the
instrument help.
10.1 Connect
This script connects to a Rohde & Schwarz signal generator using the function
rs_connect(). After establishing the connection the instrument is queried for
identification (*IDN?).
10.2 Convert_Mat2Wv
This script converts binary data read from a .mat file to a Rohde & Schwarz waveform
that can be used with the R&S Vector Signal Generator. The script expects a .mat file
containing two 1D arrays containing the I- and Q-data respectively. Additionally, the
.mat file must contain the clock frequency as a variable. The output waveform file is
transferred to the instrument's ARB and played started.
10.3 Create_IQ_Chirp
This script generates I/Q data and converts it into a Rohde & Schwarz waveform file.
For this purpose a simple linear FM chirp (sweep) is created and the resulting
waveform transferred to the instrument’s ARB.
The waveform is stored on the hard drive of the instrument. For Windows based
remote instruments (e.g. SMU, SMJ, SMATE) the storage path is “D:\”, while for Linux
based instruments (e.g. SMBV) the storage path is “/var/smbv/” or “/hdd/” (only with
hard disk option). Note that the specified storage path needs to be adjusted depending
on the instrument.
10.4 Create_IQ_AWGN
This script demonstrates the generation of an AWGN signal.
10.5 Create_IQ_MultiCarrier
This script demonstrates the generation of a multi carrier waveform file that is
transferred to the generator’s ARB and played started.
10.6 NRPZ_Instrument_Sweep
This script reads data from a NRP-Z Power Sensor that is controlled via the signal
generator (The sensor is connected to the sensor input connector of the generator). A
connection to the generator is opened and the RF power level is set to a fixed level.
During a frequency sweep from f1 to f2 at a given interval all sensor readings are
captured and plotted at the end of the test run.
10.7 NRPZ_VXIPnP_ContAv
This script shows how to access a NRP-Z Power Sensor using the R&S VXI PnP
instrument driver. The power sensor is connected to the PC with the NRP-Z3 or
NRP-Z4 USB cable. The installation of the NRP Toolkit and the VXI PnP instrument
driver is a requirement (both available free of charge at www.rohde-schwarz.com).
The example connects to the R&S Power Sensor and performs one simple average
power measurement.
10.8 NRPZ_VXIPnP_Trace
This script shows how to access a NRP-Z Power Sensor using the R&S VXI PnP
instrument driver. The power sensor is connected to the PC with the NRP-Z3 or
NRP Z4 USB cable. The installation of the NRP Toolkit and the VXI PnP instrument
driver is a requirement (both available free of charge at www.rohde-schwarz.com).
The example connects to the R&S Power Sensor and performs one trace
measurement. The measurement is untriggered and does not use any averaging. The
noise level is therefore relatively high.
10.9 Run_SCPI_Batch
This script processes a list of SCPI commands from an ASCII text file. After opening a
connection to the instrument various SCPI remote control commands are sent
consecutively to the generator which are listed in the example text file scpi.txt.
The gateway driver provided with the MATLAB Toolkit does only support the VISA
communication and functionality is limited to basic read- and write-commands.
11.2 rs_LinuxVisaDriver ()
This function is the gateway function and builds the link between MATLAB and VISA.
The open function opens and tests an instrument connection. Currently only the VISA
interface is supported and thus the second function parameter must be a valid VISA
resource string.
The return value is an index that needs to be used for all further function calls related to
this instrument. When the driver is unloaded all open connections are automatically
closed.
The close function closes the link to a previously opened instrument connection. After
calling the close function the index number becomes invalid and cannot be used any
further.
This function sends a command an instrument that is identified by the index number
obtained from a previous open call. Commands are SCPI instructions that do not return
any value from the instrument. However, one exception exists for commands
terminated on ‘*OPC?’. If this string is prevalent at the end of a command the function
automatically executes a read and evaluates the result.
This function sends a command to the instrument and then waits for the device
response. The response string is returned. The default timeout is set in the gateway
routine and cannot be changed by a function call (5 seconds).
11.3 rs_Lin_generate_wave ()
<status> = rs_Lin_generate_wave (<index>, <struct>,
<playback>, <save_local>);
Parameters
<index> session index as returned from open
<struct> I/Q data and waveform parameters
<playback> 0 = ARB is not started after transfer
1 = waveform is played in path A
2 = waveform is played in path B
<save_local> 0 = waveform is not stored on local PC
1 = waveform is stored on local PC (current directory)
This function assembles a Rohde & Schwarz waveform file from a complex vector.
Additionally, the file can be transferred to the instrument and playback started in one of
the ARBs.
11.4 rs_Lin_batch_interpret ()
[<status>, <answer>] = rs_Lin_batch_interpret (<index>,
'<batch-file>');
Parameters
<index> session index as returned from open
<batch-file> path and name of the batch-file
<status> 1 if successful
<answer> Contains the queries results in a structure
answer(x).text, where x is a consecutive number
of the queries, starting with the index one.
The highest number is the total number of queries.
This function executes a series of SCPI commands
or queries from a text file.
Send *IDN?
Receive result
Close connection
Close connection
Close connection
13 ADS Support
The ADS sub directory of the toolkit contains a MATLAB routine that can be called from
ADS in order to convert a complex vector into a Rohde & Schwarz ARB waveform file.
The MATLAB routine also allows the user to start the waveform playback in path A or B
and set the RF frequency and level.
13.1 Installation
On Microsoft Windows systems ADS only requires that the PATH environment variable
is set to the \bin\win32 sub directory of the MATLAB installation.
PATH=<matlabroot>\bin\win32;%PATH%
Additionally, it must be ensured that all toolkit scripts can be found from MATLAB.
13.2 Usage
The first step is to place a Matlab_M object into your schematic. This object directly
runs a MATLAB .m script during a simulation.
Next, a BusMerge5 object is required to combine the input parameters for the R&S
Matlab_M object.
Connect the two objects as shown below and edit the Matlab_M properties according to
the list below.
Script Directory =
MatlabSetUp =
MatlabFunction = output#1=rs_ADS_IQSink( input#1, input#2,
input#3, input#4, input#5,
'GPIB0::28::INSTR', 'D:/', 'test.wv',
'comment', 'copyright')
MatlabWrapUp =
The property MatlabFunction defines the call to MATLAB as well as all input and return
parameters. The placeholder input# is used for one of the parameters passed to the
BusMerge5 object. In the example above the VISA resource string is set to a device
connected to the primary GPIB board and set to address 28. The MATLAB routine
creates a waveform file locally and copies it to the specified location under the given
name (D:\test.wv in the example above).
Finally, the input values need to be provided to the BusMerge5 block as indicated in the
following picture. Const objects may be used for this purpose.
It is also required to pack the input data stream into a vector. This can be done by using
the PackCx_M object from ADS.
The example above uses QPSK encoded data and thus the length of the vector is set
to DefaultNumericStop/4 (no oversampling used, DefaultNumericStop sets number of
input bits).
The list below outlines the input parameters to the BusMerge block.
The MATLAB script rs_ADS_IQSink() performs the following actions when called with
the above parameters.
The function uses the National Instruments VISA interface by default. The MATLAB
code needs to be changed if other interfaces are used.
Regional contact
Europe, Africa, Middle East
+49 1805 12 42 42* or +49 89 4129 137 74
customersupport@rohde-schwarz.com
North America
1-888-TEST-RSA (1-888-837-8772)
customer.support@rsa.rohde-schwarz.com
Latin America
+1-410-910-7988
customersupport.la@rohde-schwarz.com
Asia/Pacific
+65 65 13 04 88
customersupport.asia@rohde-schwarz.com
www.rohde-schwarz.com