MATLAB Toolkit For R&S Signal Generators Application Note

Transcription

MATLAB Toolkit forR&S Signal GeneratorsApplication NoteProducts: R&S SMW200A R&S SMBV100A R&S SMU200A R&S AFQ100A R&S SMJ100A R&S AFQ100B R&S SMATE200A R&S SMA100A R&S AMU200A R&S SMB100A R&S SMC100AT. Röder, C. Tröster24.4.2013Application NoteThis 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.

NoticesTable of Contents9E1.Notices . 32.Overview . 43.Features . 44.System Requirements . 51.2Hardware .51.3Software .55.Windows XP Installation. 61.4Unpacking The Files .61.5Setting The Path In MATLAB.66.Linux Installation. 81.6Prerequisites.81.7Unpacking The Files .81.8VISA Installation .81.9USB Support .97.VISA Resource Strings . 108.R&S Toolkit Functions. 111.10rs connect.m .111.11rs check instrument errors.m.131.12rs send comand.m.131.13rs send query.m.131.14rs batch interpret.m.141.15rs generate wave.m .151.16rs visualize.m .169.Example Scripts . 1710.ADS Support. 181.17Installation.181.18Usage.1811.Additional Information. 22Rohde & SchwarzMATLAB Toolkit for R&S Signal Generators 2

Notices1.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 asAFQ. The R&S AMU200A Baseband Signal Generator and Fading Simulator is referredto 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. KG9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 3

Overview2.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 systemsOpen device connections to R&S Signal GeneratorsSend SCPI commands or queriesProcess a script with SCPI commands or queriesCreate an R&S waveform file from IQ data and send the waveform file to theinstrumentAccess instruments from within Agilent ADS (Advanced Design System)9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 4

System Requirements4.System Requirements1.2 HardwareThe MATLAB requirements (CPU, memory, hard drive)For the instrument remote control (depending on instrument)– 100MBit LAN– GPIB hardware– USB interface1.3 SoftwareThe 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.0Linux 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.19ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 5

Windows XP Installation5.Windows XP Installation1.4 Unpacking The FilesThe MATLAB Toolkit comes as a set of files bundled in a ZIP archive.‘RS MATLAB Toolkit version number .zipFirst, create a new folder under your MATLAB toolbox directory, e.g.C:\Program Files\MATLAB\R2007a\toolbox\RsMatlabToolkitThe contents of the archive should now be unpacked into this directory.1.5 Setting The Path In MATLABFor 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 dialog9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 6

Windows XP InstallationNote: 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 n32in the MATLAB directory, create a new directory called backup and move every dllexcept mwnigpib.dll and mwnivisa.dll to the backup directory.9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 7

Linux Installation6.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 PrerequisitesLinux distribution with kernel sources and symbols installedVISA installation package, e.g. from National Instruments1.7 Unpacking The FilesThe 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/RsMatlabToolkitAfter the files are unpacked follow the Step ‘Set the path to the toolkit in MATLAB’ fromthe Windows installation procedure.1.8 VISA InstallationThis 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 prepareNext, mount the National Instruments ISO image into a folder.# mkdir /media/visa# mount –t iso9660 –o loop,ro imagefile /media/visa# cd /media/visaRun the National Instruments installer and make sure to add the ‘development’ option.# ./INSTALL9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 8

Linux InstallationYou should now have a working VISA installation. Verify your installation by invokingthe NIvisaic or visaconf tools.# NIvisaic# visaconf1.9 USB SupportIn 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 usbIf 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.# sions.shEnter 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.9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 9

VISA Resource Strings7.VISA Resource StringsThe general format of the USB VISA resource string isUSB:: vendor id :: product id :: serial number ::INSTRThe 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 IDsInstrumentDevice 0x54SMC100A0x6EThe list represents all R&S Signal Generators that support USB remote control at thetime of writing.9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 10

R&S Toolkit Functions8.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 OverviewFunction / .m FileDescriptionrs connect.mCreate GPIB or VISA object for an instrumentor open TCP/IP socket connectionand verify the linkrs check instrument errors.mQuery the instrument’s error queue by repeatedlysending SYST:ERR?rs send command.mSend a SCPI command to the instrumentrs send query.mSend a SCPI command to the instrument and querythe resultrs batch interpret.mProcess a file containing SCPI commandsrs generate wave.mGenerate waveform file from complex vector andtransfer to instrumentrs visualize.mVisualizes 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.mThe 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.9Ers 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 ')Rohde & SchwarzMATLAB Toolkit for R&S Signal Generators 11

R&S Toolkit FunctionsGPIB parameters board number primary address secondary address GPIB board number (usually 0)GPIB bus address of the instrumentThe secondary GPIB bus addressof the instrument (optional)VISA parameters VISA resource string The VISA resource string describes thedevice as well as the interface type.TCP/IP parameters hostname The instrument host name or the IP addressReturn values status object 1 if successfulThe handle to the instrumentThe 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.9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 12

R&S Toolkit Functions1.11 rs check instrument errors.mThe 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 successfulExample 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.mThe function rs send command() sends a single SCPI command to a previouslyconnected instrument. status rs send command( object , ' command ' );Parameters object command The instrument object returned by rs connect()SCPI command, e.g. ‘FREQ 1.2GHz’Return value status 1 if successfulExample code [err, instrObj] rs connect( 'gpib', 'ni', 0, 28 ); err rs send command( instrObj, '*RST' );1.13 rs send query.mThe 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 ' );Parameters9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 13

R&S Toolkit Functions object command Return values status answer The instrument object returned by rs connect()SCPI command, e.g. ‘*IDN?’1 if successfulContains the answer from the instrumentExample code [err, instrObj] rs connect( 'gpib', 'ni', 0, 28 ); [err, answer] rs send query( instrObj, '*IDN?' );1.14 rs batch interpret.mThis function processes a series of SCPI commands or queries from a text file.[ status , answer ] rs batch interpret( object ,' batch-file ' );Parameters object batch-file Return values status answer The instrument object returned by rs connect()Path and name of the batch-file1 if successfulContains the queries results in a structureanswer(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?'9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 14

R&S Toolkit Functions1.15 rs generate wave.mThis 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 struct playback save local Return value status The struct formatI dataQ rkerlist.fourclockpathfilenamecommentThe instrument object returned by rs connect()If this number is set to 0 the waveform is onlystored locally and not sent to the instrument.I/Q data and waveform parameters0 ARB is not started after transfer1 waveform is activated in path A2 waveform is activated in path B0 waveform is not stored on local PC1 waveform is stored on local PC (current directory)1 if successful1D array of I values1D array of Q values2D array marker liste.g.PositionValue00101500- [[0 0];[10 1];[50 0]]2D array marker list2D array marker list2D array marker listdesired clock rate in Hzstorage path in the remote deviceincluding drive letter: e.g. “D:\Files”waveform name in the remote devicefile extension “.wv” is (mandatory)(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.9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 15

R&S Toolkit Functions1.16 rs visualize.mThis function plots the I/Q values.[ status ] rs visualize( FSample, I data, Q data );9EParameters FSample I data Q data The sample rate in Hz1D array with I values1D array with Q valuesReturn value status 1 if successfulRohde & SchwarzMATLAB Toolkit for R&S Signal Generators 16

Example Scripts9.Example ScriptsThe example scripts demonstrate the use of the toolkit functions. The following listprovides a brief overview of the examples.Script Overview9EScript / .m FileFunctionalityConnect.mConnect to instrument and send *IDN? and *OPT? Thisexample also describes the various hardwareinterfaces in detail.Create IQ AWGN.mCreate a noise (AWGN) signal and load to theinstrument’s ARB.Create IQ Chirp.mCreate a frequency sweep signal and load to theinstrument’s ARB.Create IQ MultiCarrier.mCreate a multi carrier signal and load to theinstrument’s ARB.Create IQ Pulse.mCreate a pulsed signal and load to theinstrument’s ARB.Create IQ TwoTone.mCreate a two tone signal and load to theinstrument’s ARB.Convert Mat2Wv.mRead data from a .mat file and convert into aRohde & Schwarz waveform file for use withthe instruments ARBRun SCPI Batch.mProcess a list of SCPI commands thatare read from a text fileRohde & SchwarzMATLAB Toolkit for R&S Signal Generators 17

ADS Support10.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 InstallationOn 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 UsageThe 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.9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 18

ADS SupportConnect the two objects as shown below and edit the Matlab M properties accordingto the list below.Script DirectoryMatlabSetUpMatlabFunctionMatlabWrapUp output#1 rs ADS IQSink( input#1, input#2,input#3, input#4, input#5,'GPIB0::28::INSTR', 'D:/', 'test.wv','comment', 'copyright') 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).9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 19

ADS SupportFinally, 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 dataClock rate in HzPlayback path for instrument 0 none, 1 A, 2 BRF Frequency in HzRF Level in HzThe MATLAB script rs ADS IQSink() performs the following actions when called withthe above parameters.Open the VISA based instrument connectionProcess complex vector and turn into local waveform fileTransfer the waveform file block wise to the instrumentStart playback on instrumentSet RF parameters9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 20

ADS SupportClose the instrument connectionThe function uses the National Instruments VISA interface by default. The MATLABcode needs to be changed if other interfaces are used.9ERohde & SchwarzMATLAB Toolkit for R&S Signal Generators 21

Additional Information11.9EAdditional Information 1GP61R&S MATLAB Toolkit for R&S NRP-Z Senors1MA171How to use Rohde & Schwarz Instruments in MATLAB1EF46Using MATLAB for Remote Control and Data Capturewith R&S Spectrum and Network Analyzers1EF51Using R&S Signal, Spectrum and Network Analyzers with MATLAB Rohde & SchwarzMATLAB Toolkit for R&S Signal Generators 22

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 commitmentEnergy-efficient productsContinuous improvement inenvironmental sustainabilityISO 14001-certified environmentalmanagement systemRegional contactEurope, Africa, Middle East 49 89 4129 137 74customersupport@rohde-schwarz.comNorth America1-888-TEST-RSA .comLatin America Asia/Pacific 65 65 13 04 88customersupport.asia@rohde-schwarz.comThis 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 – 13777www.rohde-schwarz.com

Notices 9E Rohde & Schwarz MATLAB Toolkit for R&S Signal Generators 3 1. Notices The following abbreviations are used throughout this application note. The R&S fi MATLAB fi Toolkit for R&S fi Signal Generators is referred to as MATLAB Toolkit or toolkit. The R&S fi SMW200A Vector Signal Generator is referred to as SMW. The R&S fi SMU200A Vector Signal Generator is referred to as SMU.