MATLAB Toolkit forR&S® Signal GeneratorsApplication NoteProducts:
| R&SSMW200A
| R&SSMU200A
| R&SSMJ100A
| R&SSMATE200A
| R&SAMU200A
| R&SSMBV100A
| R&SAFQ100A
| R&SAFQ100B
| R&SSMA100A
| R&SSMB100A
| R&SSMC100A
This R&S MATLAB® Toolkit provides routinesfor remote controlling Rohde & Schwarz SignalGenerators from MATLAB® scripts.Additionally, I/Q data can be turned intoRohde & Schwarz waveform files for use withthe instrument’s ARB option. This applicationnote describes the installation and use of thisR&S MATLAB® Toolkit on Microsoft Widowsand Linux based systems.
Appli
catio
nNo
te
T.Rö
der,
C.Tr
öster
24.4.
2013
Notices
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 2
Table of Contents1. Notices .................................................................................... 3
2. Overview ................................................................................. 4
3. Features .................................................................................. 4
4. System Requirements ........................................................... 51.2 Hardware .......................................................................................................5
1.3 Software ........................................................................................................5
5. Windows XP Installation........................................................ 61.4 Unpacking The Files ....................................................................................6
1.5 Setting The Path In MATLAB.......................................................................6
6. Linux Installation.................................................................... 81.6 Prerequisites.................................................................................................8
1.7 Unpacking The Files ....................................................................................8
1.8 VISA Installation ...........................................................................................8
1.9 USB Support .................................................................................................9
7. VISA Resource Strings ........................................................ 10
8. R&S Toolkit Functions......................................................... 111.10 rs_connect.m ..............................................................................................11
1.11 rs_check_instrument_errors.m.................................................................13
1.12 rs_send_comand.m....................................................................................13
1.13 rs_send_query.m........................................................................................13
1.14 rs_batch_interpret.m..................................................................................14
1.15 rs_generate_wave.m ..................................................................................15
1.16 rs_visualize.m.............................................................................................16
9. Example Scripts ................................................................... 17
10. ADS Support......................................................................... 181.17 Installation...................................................................................................18
1.18 Usage...........................................................................................................18
11. Additional Information......................................................... 22
Notices
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 3
1.NoticesThe following abbreviations are used throughout this application note.
● The R&S® MATLAB® Toolkit for R&S® Signal Generators is referred to as MATLABToolkit or toolkit.
● The R&S® SMW200A Vector Signal Generator is referred to as SMW.● 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.
MATLAB® is a U.S. registered trademark of The Math Works, Inc.
Agilent® and Agilent® Eesof ADS are registered trademarks of Agilent Technologies.
Rohde & Schwarz® is a registered trademark of Rohde & Schwarz GmbH & Co. KG
Overview
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 4
2.OverviewMATLAB is widely used for the simulation of communication systems and the creationor analysis of custom signals. This toolkit provides functions that simplify the remotecontrol of Rohde & Schwarz instruments from MATLAB scripts. These functions coverthe most common tasks, such as sending SCPI commands to the instrument andreading responses back from it. Additional functions convert I/Q data into R&Swaveform files and transfer these files to the instrument’s ARB. A set of examplescripts demonstrate the use of the toolkit functions in various applications. The toolkitsupports remote control via GPIB hardware, raw TCP/IP socket connections, or theVISA (Virtual Instrument Software Architecture) interface.
3.FeaturesThe toolkit provides the following functionality.
● Support Microsoft Windows and Linux based systems● Open device connections to R&S Signal Generators● Send SCPI commands or queries● Process a script with SCPI commands or queries● Create an R&S waveform file from IQ data and send the waveform file to the
instrument● Access instruments from within Agilent ADS (Advanced Design System)
System Requirements
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 5
4.System Requirements
1.2 Hardware
● The MATLAB requirements (CPU, memory, hard drive)● For the instrument remote control (depending on instrument)
– 100MBit LAN– GPIB hardware– USB interface
1.3 Software
The MATLAB Toolkit can be used on Microsoft Windows XP or Linux operatingsystems. The following configuration was tested by Rohde & Schwarz.
● Microsoft Windows XP based system– Windows XP, Service Pack 2– MATLAB 7.4.0 R2007a– MATLAB Instrument Control Toolbox– National Instruments VISA Version 4.0
● Linux based system– Linux kernel 2.6.18, e.g. Open SuSE 10.2– MATLAB R2009a
(MATLAB Instrument Control Toolbox provided from R2009a on)– National Instruments VISA Version 4.1
Windows XP Installation
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 6
5.Windows XP Installation
1.4 Unpacking The Files
The MATLAB Toolkit comes as a set of files bundled in a ZIP archive.
‘RS_MATLAB_Toolkit_<version number>.zip
First, create a new folder under your MATLAB toolbox directory, e.g.
C:\Program Files\MATLAB\R2007a\toolbox\RsMatlabToolkit
The contents of the archive should now be unpacked into this directory.
1.5 Setting The Path In MATLAB
For a convenient use of the toolkit functions it is required to add the installation path ofthe toolkit scripts to the MATLAB environment. This can be done by selectingFile → Set Path from the menu bar. This brings up the ‘Set Path’ dialog where the newpath is added using the Add Folder… button.
Figure 1 MATLAB Set Path dialog
Windows XP Installation
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 7
Note: When using MATLAB 7.0 (R14) it is required to remove unused instrumentdrivers. This is a confirmed problem in MATLAB 7.0 (R14) in the way that MATLABinterfaces with GPIB cards.
To remove the drivers please open the directory
\toolbox\instrument\instrumentadaptors\win32
in the MATLAB directory, create a new directory called backup and move every dllexcept mwnigpib.dll and mwnivisa.dll to the backup directory.
Linux Installation
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 8
6.Linux InstallationStarting with version R2009a MATLAB provides the Instrument Control Toolbox onLinux installation. Using these toolbox scripts is recommended for all instrumentcommunication because it allows writing platform independent code and simplifiesinstrument access greatly.
1.6 Prerequisites
● Linux distribution with kernel sources and symbols installed● VISA installation package, e.g. from National Instruments
1.7 Unpacking The Files
The toolkit comes as a set of files bundled in a ZIP archive. Extract all files into a pathin your MATLAB toolbox directory.
# md /opt/matlab2009/toolbox/RsMatlabToolkit
# unzip <archive.zip> \-d /opt/matlab2006/toolbox/RsMatlabToolkit
After the files are unpacked follow the Step ‘Set the path to the toolkit in MATLAB’ fromthe Windows installation procedure.
1.8 VISA Installation
This brief guide was developed for an Open SuSE 10.2 installation and the NationalInstruments VISA package. Please see the VISA web site (www.ni.com/visa) fordownload and details about license and installation.
First, prepare your kernel sources as root user.
# cd /usr/src/linux# make cloneconfig# make prepare
Next, mount the National Instruments ISO image into a folder.
# mkdir /media/visa# mount –t iso9660 –o loop,ro <imagefile> /media/visa# cd /media/visa
Run the National Instruments installer and make sure to add the ‘development’ option.
# ./INSTALL
Linux Installation
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 9
You should now have a working VISA installation. Verify your installation by invokingthe NIvisaic or visaconf tools.
# NIvisaic# visaconf
1.9 USB Support
In order to use USB for VISA remote control the current kernel must support usbfs oron older kernels usbdevfs. Verify that this file system is mounted by using the mountcommand.
# mount | grep usb
If usbfs is mounted a line, such as ‘usbfs on /proc/bus/usb type usbfs …’ shouldappear.By default only the root user is allowed for raw access to USB devices. In order toallow access to normal users National Instruments provides a script that configuresyour 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.
Now connect the instrument to the USB port.
VISA Resource Strings
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 10
7.VISA Resource StringsThe general format of the USB VISA resource string is
USB::<vendor id>::<product id>::<serial number>::INSTR
The vendor ID for all Rohde & Schwarz devices is 0x0AAD. The product ID dependson the instrument and can be taken from the list below.
USB Device IDs
Instrument Device ID
SMW200A 0x92
AFQ100A 0x4B
AFQ100B 0x66
AMU200A 0x55
SMATE200A 0x46
SMBV100A 0x5F
SMF100A 0x47
SMA100A 0x48
SMB100A 0x54
SMC100A 0x6E
The list represents all R&S Signal Generators that support USB remote control at thetime of writing.
R&S Toolkit Functions
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 11
8.R&S Toolkit FunctionsThe toolkit provides various scripts for basic instrument access. The following listsummarizes these functions. Each function is located in a MATLAB script using thename of the function.
Function Overview
Function / .m File Description
rs_connect.m Create GPIB or VISA object for an instrumentor open TCP/IP socket connectionand verify the link
rs_check_instrument_errors.m Query the instrument’s error queue by repeatedlysending SYST:ERR?
rs_send_command.m Send a SCPI command to the instrument
rs_send_query.m Send a SCPI command to the instrument and querythe result
rs_batch_interpret.m Process a file containing SCPI commands
rs_generate_wave.m Generate waveform file from complex vector andtransfer to instrument
rs_visualize.m Visualizes I/Q data by generating a time domain, FFT,and I/Q plane plot.
The next paragraph explains the syntax and use of these functions.
1.10 rs_connect.m
The function rs_connect() sets up the instrument connection and tests the link. Itreturns a handle to the remote controlled instrument. The connection can beestablished using the GPIB or VISA interface as well as via a raw TCP/IP socketconnection. The recommended interface type is VISA.
rs_connect ('gpib', <'advantech|agilent|cec|contec|ics|iotech|keithley|mcc|ni'>,<board number>, <primary address>[, <secondary address>])
rs_connect ('visa', '<ni|agilent|tek>','<visa resource string>')
rs_connect ('tcpip', '<hostname>')
R&S Toolkit Functions
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 12
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 or the IP address
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 softwareinterface. The function call for opening device number 28 connected to the firstNational Instruments GPIB card is
>> [err, instrObj] = rs_connect( 'gpib', 'ni', 0, 28 );
VISA offers more flexibility over direct GPIB connections as it allows the use ofdifferent interface types. Please consult your Rohde & Schwarz instrument manual ordata sheet for details about which remote control interface is supported by yourinstrument.
Please see the documentation of your VISA installation for details about the VISAresource strings.
Note:LAN based remote control requires that the instrument’s firewall is disabled. This, forexample, applies to the Microsoft Windows based instruments SMU, SMJ, andSMATE. The Linux based instruments, such as the SMBV do not have an internalfirewall.
R&S Toolkit Functions
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 13
1.11 rs_check_instrument_errors.m
The function rs_check_instrument_errors() sends SYST:ERR? queries to theinstrument until the error queue is entirely cleared.
<status> = rs_check_instrument_errors( <object> );
Parameters<object> The instrument object returned by rs_connect()
Return value<status> 1 if successful
Example code>> [err, instrObj] = rs_connect( 'gpib', 'ni', 0, 28 );>> err = rs_send_command( instrObj, 'XXX' );>> err = rs_check_instrument_errors( instrObj );-113,"Undefined header;XXX"
1.12 rs_send_comand.m
The function rs_send_command() sends a single SCPI command to a previouslyconnected instrument.
<status> = rs_send_command( <object>, '<command>' );
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' );
1.13 rs_send_query.m
The function rs_send_query() works similar to rs_send_command() with the exceptionthat an answer from the instrument is expected after the command has been sent.
[<status>, <answer>] = rs_send_query( <object>, '<command>' );
Parameters
R&S Toolkit Functions
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 14
<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?' );
1.14 rs_batch_interpret.m
This function processes a series of SCPI commands or queries from a text file.
[<status>, <answer>] = rs_batch_interpret( <object>,'<batch-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 numberof the queries, starting with the index one.The highest number is the total number of queries.
Example batch file (scpi.txt)% Comment line*IDN?FREQ 1.2 GHzPOW -10.0 dBmOUTP:STAT ONSYST:ERR?
Example code>> [err, answer] = rs_batch_interpret( instrObj, \
'scpi.txt' );
answer(1).text contains the return information from '*IDN?'answer(2).text contains the return information from 'SYST:ERR?'
R&S Toolkit Functions
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 15
1.15 rs_generate_wave.m
This function builds a waveform file from an I/Q vector. It also sends the generated fileto the instrument’s mass memory system and optionally starts the ARB in path A or B.
[<status>] = rs_generate_wave( <object>, <struct>,<playback>, <save_local> );
Parameters<object > The instrument object returned by rs_connect()
If this number is set to 0 the waveform is onlystored 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 A2 = waveform is activated in path B
<save_local> 0 = waveform is not stored on local PC1 = waveform is stored on local PC (current directory)
Return value<status> 1 if successful
The <struct> formatI_data 1D array of I values (mandatory)Q_data 1D array of Q values (mandatory)markerlist.one 2D array marker list (optional)
e.g. Position Value0 010 150 0
-> [[0 0];[10 1];[50 0]]markerlist.two 2D array marker list (optional)markerlist.three 2D array marker list (optional)markerlist.four 2D array marker list (optional)clock desired clock rate in Hz (mandatory)path storage path in the remote device (mandatory)
including drive letter: e.g. “D:\Files”filename waveform name in the remote device (mandatory)
file extension “.wv” is mandatorycomment Comment (optional)
Markers are digital output signals that are generated synchronous to the signal output.These signals can be used for synchronization of other devices. For more informationplease see the instrument’s user manual.
R&S Toolkit Functions
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 16
1.16 rs_visualize.m
This function plots the I/Q values.
[<status>] = rs_visualize( FSample, I_data, Q_data_);
Parameters<FSample> The sample rate in Hz<I_data> 1D array with I values<Q_data> 1D array with Q values
Return value<status> 1 if successful
Example Scripts
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 17
9.Example ScriptsThe example scripts demonstrate the use of the toolkit functions. The following listprovides a brief overview of the examples.
Script Overview
Script / .m File Functionality
Connect.m Connect to instrument and send *IDN? and *OPT? Thisexample also describes the various hardwareinterfaces in detail.
Create_IQ_AWGN.m Create a noise (AWGN) signal and load to theinstrument’s ARB.
Create_IQ_Chirp.m Create a frequency sweep signal and load to theinstrument’s ARB.
Create_IQ_MultiCarrier.m Create a multi carrier signal and load to theinstrument’s ARB.
Create_IQ_Pulse.m Create a pulsed signal and load to theinstrument’s ARB.
Create_IQ_TwoTone.m Create a two tone signal and load to theinstrument’s ARB.
Convert_Mat2Wv.m Read data from a .mat file and convert into aRohde & Schwarz waveform file for use withthe instruments ARB
Run_SCPI_Batch.m Process a list of SCPI commands thatare read from a text file
ADS Support
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 18
10. ADS SupportThe ADS sub directory of the toolkit contains a MATLAB routine that can be calledfrom ADS in order to convert a complex vector into a Rohde & Schwarz ARB waveformfile. The MATLAB routine also allows the user to start the waveform playback in path Aor B and set the RF frequency and level.
1.17 Installation
On Microsoft Windows systems ADS only requires that the PATH environment variableis 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.
1.18 Usage
The first step is to place a Matlab_M object into your schematic. This object directlyruns a MATLAB .m script during a simulation.
Next, a BusMerge5 object is required to combine the input parameters for the R&SMatlab_M object.
ADS Support
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 19
Connect the two objects as shown below and edit the Matlab_M properties accordingto 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 returnparameters. The placeholder input# is used for one of the parameters passed to theBusMerge5 object. In the example above the VISA resource string is set to a deviceconnected to the primary GPIB board and set to address 28. The MATLAB routinecreates a waveform file locally and copies it to the specified location under the givenname (D:\test.wv in the example above).
ADS Support
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 20
Finally, the input values need to be provided to the BusMerge5 block as indicated inthe 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 byusing the PackCx_M object from ADS.The example above uses QPSK encoded data and thus the length of the vector is setto DefaultNumericStop/4 (no oversampling used, DefaultNumericStop sets number ofinput bits).
The list below outlines the input parameters to the BusMerge block.
● Complex vector of I/Q data● Clock rate in Hz● Playback path for instrument 0=none, 1=A, 2=B● RF Frequency in Hz● RF Level in Hz
The MATLAB script rs_ADS_IQSink() performs the following actions when called withthe above parameters.
● Open the VISA based instrument connection● Process complex vector and turn into local waveform file● Transfer the waveform file block wise to the instrument● Start playback on instrument● Set RF parameters
ADS Support
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 21
● Close the instrument connection
The function uses the National Instruments VISA interface by default. The MATLABcode needs to be changed if other interfaces are used.
Additional Information
9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 22
11. Additional Information1GP61 R&S MATLAB® Toolkit for R&S® NRP-Z Senors
1MA171 How to use Rohde & Schwarz Instruments in MATLAB®
1EF46 Using MATLAB® for Remote Control and Data Capturewith R&S Spectrum and Network Analyzers
1EF51 Using R&S Signal, Spectrum and Network Analyzers with MATLAB®
About Rohde & SchwarzRohde & Schwarz is an independent groupof companies specializing in electronics. It isa leading supplier of solutions in the fields oftest and measurement, broadcasting,radiomonitoring and radiolocation, as well assecure communications. Established morethan 75 years ago, Rohde & Schwarz has aglobal presence and a dedicated servicenetwork in over 70 countries. Companyheadquarters are in Munich, Germany.
Environmental commitment● Energy-efficient products● Continuous improvement in
environmental sustainability● ISO 14001-certified environmental
management system
Regional contactEurope, Africa, Middle East+49 89 4129 137 [email protected]
North America1-888-TEST-RSA (1-888-837-8772)[email protected]
Latin [email protected]
Asia/Pacific+65 65 13 04 [email protected]
This application note and the suppliedprograms may only be used subject to theconditions of use set forth in the downloadarea of the Rohde & Schwarz website.
R&S® is a registered trademark of Rohde & SchwarzGmbH & Co. KG; Trade names are trademarks of theowners.
Rohde & Schwarz GmbH & Co. KGMühldorfstraße 15 | D - 81671 MünchenPhone + 49 89 4129 - 0 | Fax + 49 89 4129 – 13777
www.rohde-schwarz.com