FAQs from Rohde & Schwarz

Capturing a trace in Spectrum Analyzer mode using Matlab

Question

Following Matlab script gives a fast reference on how move the trace data from a FSV3030 R&S Spectrum Analyzer into the Matlab workspace.

A simple non modulated CW signal of 1 GHz and -30 dbm was used as example for the proof of concept.

Answer

+++Code+++

% Preconditions:
% - Installed latest R&S VISA
clc;
analyzer_handle = visa('rs','TCPIP::10.205.0.101::INSTR'); %visa connection, toolbox required
analyzer_handle.OutputBufferSize = 1000000; %output buffer size in bytes
analyzer_handle.InputBufferSize = 1000000; %input buffer size in bytes
fopen(analyzer_handle);

fprintf(analyzer_handle,'*RST;*WAI');
fprintf(analyzer_handle,'*IDN?');
a=fscanf(analyzer_handle);
disp(a);

fprintf(analyzer_handle,'INIT:CONT OFF'); %Selects single sweep mode.

%--------------Configuring the Frequency and Span-------------
fcenter=1000000000;
fprintf(analyzer_handle,'FREQ:CENT %d',fcenter); %Defines the center frequency
fspan=5000000;
fprintf(analyzer_handle,'FREQ:SPAN %d',fspan); %Sets the span

%--------------Configuring the Sweep--------------------------
fprintf(analyzer_handle,'SENS:SWE:COUN 1'); %Defines 1 sweep
points=10000; %nr of points sets resolution of the trace
fprintf(analyzer_handle, 'SENS:SWE:POIN %d',points);

%--------------Configuring the Bandwidth----------------------
fprintf(analyzer_handle,'BAND:AUTO OFF');
fprintf(analyzer_handle,'BAND 100000'); %Defines the RBW
fprintf(analyzer_handle,'BAND:VID 500kHz'); %Decouples the VBW from the RBW and decreases it to smooth the trace.

%--------------trace acquisition-----------------------------
timeout=30; %timeout in seconds
set(analyzer_handle,'Timeout',timeout); %timeout increased before acquisition to avoid sync errors
fprintf(analyzer_handle,'INIT:IMM;*WAI');
fprintf('Fetching waveform ...\n ');
fprintf(analyzer_handle,':FORM REAL,32');
fprintf(analyzer_handle,':TRAC? TRACE1;*WAI');
data=binblockread(analyzer_handle,'float32');
fread(analyzer_handle,1); %fread removes the extra terminator in the buffer
timeout=1; %timeout in seconds goes back to a normal value
set(analyzer_handle,'Timeout',timeout);

%--------------Presentation of the trace in a plot---------
fstart=fcenter-fspan/2;
fstop=fcenter+fspan/2;
resolution=fspan/points;
points_array=1:1:points;

for c = 1:points %scale time axis and power data

points_array(1,c)=points_array(1,c)*resolution;
points_array(1,c)=points_array(1,c) + fstart;

end

plot(points_array,data);
title('SA Spectrum Acquisition')
xlabel('frequency domain [Hz]')
ylabel('power [dbm]')

%--------------error check up----------------------
fprintf(analyzer_handle,'SYST:ERR?');
a=fscanf(analyzer_handle);
disp(a);

fclose(analyzer_handle);

+++

Below the trace observed in the Spectrum Analyzer after the above script got executed with Matlab.

Capturing a trace in Spectrum Analyzer mode using Matlab

Here the output of the code which presents the trace data as a proof of concept.

Capturing a trace in Spectrum Analyzer mode using Matlab
Capturing a trace in Spectrum Analyzer mode using Matlab

In addition, one can use R&S Visa Tester to revise in detail the process of acquiring the data points, for this particular case 10000 points were acquired, each given as a 4-byte float value. This is why one reads 40000 bytes in the log at the beginning of the capture so that the acquisition buffer gets set accordingly,

References:

-FSV3030 Product Page
https://www.rohde-schwarz.com/de/produkt/fsv3000-produkt-startseite_63493-601503.html

-Hints and Tricks for Remote Control of Spectrum and Network Analyzers - Application Note 1EF62_1E
https://www.rohde-schwarz.com/applications/hints-and-tricks-for-remote-control-of-spectrum-and-network-analyzers-application-note_56280-15635.html

-Remote Control and Instrument Drivers:
https://www.rohde-schwarz.com/driver-pages/remote-control/drivers-remote-control_110753.html