No BSD License  

Highlights from
RSA3000 TImed Sweep

RSA3000 TImed Sweep

by

 

22 Jun 2008 (Updated )

This program is designed to record a spectrum trace from a Tektronix RSA3000A/B at a fixed interval

ParseBinary32Bit_SCPI( rsa )
function data = ParseBinary32Bit_SCPI( rsa )

% ParseBinary32Bit_SCPI		Parses a binary stream from a Tektronix RSA
%
% data = ParseBinary32Bit_SCPI( rsa )
%
% This function parses the binary stream that is returned by a number of 
% SCPI queries in Tektronix real-time spectrum analyzers. The text header
% will be read and then the binary data acquired, with the binary data
% returned as an output. If the binary data being read is complex data, the
% data will be returned as a real vector that has the real data interleaved
% with the imaginary data:
%	dataReal(1) dataImag(1) dataReal(2) dataImag(2) ...
%
% Inputs:
%	rsa		The VISA object that points to the RSA
%
% Outputs:
%	data	The binary data acquired from the RSA. If the data being read 
%			is complex, it will be returned as a real-valued vector with 
%			the real data interleaved with the imaginary data:
%				dataReal(1) dataImag(1) dataReal(2) dataImag(2) ...
%
% Version:			1.01
% Last Modified:	May 4, 2007
% Tested with:		MATLAB R2007a
% Change Log:		v1.01
%						* inputBufferSize no longer needed as input

inputBufferSize = get( rsa, 'InputBufferSize' );

% The data we will parse has the following format:
% #<Num_digit><Num_byte><IData 1><QData 1><IData 2><QData 2> ... <IData
% N><QData N>
%
% where:
%	<Num_digit>	Number of digits in the <Num_byte> field
%	<Num_byte>	Number of bytes to follow
%	<IData 1>	I channel in V (4 byte little-endian floating
%				point format)
%
byteWidth	= 4;	% 32 bit data (single precision)
strTemp		= fread( rsa, 1, 'char');		% Get rid of the # sign
numDigits	= str2double( char( fread( rsa, 1, 'char') ) );
numBytes	= str2double( char( fread( rsa, numDigits, 'char' ) ) );
	
numSamples = (numBytes / byteWidth);

data = zeros(1,numSamples);
numBufferSamples = inputBufferSize / byteWidth;
if numBufferSamples > numSamples,
	numBufferSamples = numSamples;
end
numReadIterations = floor( numSamples / numBufferSamples);
numRemainingSamples = numSamples - numReadIterations * numBufferSamples;
i2 = 0;
for i=1:numReadIterations,
	i1 = i2 + 1;
	i2 = i1 + numBufferSamples - 1;
	data(i1:i2) = fread( rsa, numBufferSamples, 'single' );
end
if numRemainingSamples > 0,
	i1=i2+1;
	i2=i1+numRemainingSamples-1;
	data(i1:i2) = fread( rsa, numRemainingSamples, 'single' );
end

% Finish the read by reading the terminal character
strTemp		= fread( rsa, 1, 'char');	

return

Contact us