Example of Metafile and C++ code are shown below. The MATLAB script is used to read a WCAP file from the instrument and unpack the data into a MATLAB array. The C++ sample program uses the SCPI commands to initiate a capture and save it directly to the PC.
MATLAB Script (getdata_simple_24.m)
function Data = getdata_simple_24()
% target file has 24 bit data
% I/Q both contained in same file, 1-by-1
% use with *.wcap files captured manually on unit
% Data contains complex-valued contents of filename.wcap
fidIQ = fopen('filename.wcap','r');
% fetch # of complex data samples
stat = fseekStr(fidIQ, '"CaptureSample" Value="');
if stat == -1
disp 'ERROR: data size could not be found in file';
fclose(fidIQ);
return;
else
samples = fscanf(fidIQ, '%d', 1);
end
% fetch sample rate
stat = fseekStr(fidIQ, '"SamplingClock" Value="');
if stat == -1
disp 'ERROR: sample rate could not be found in file';
samp_rate = 1;
else
samp_rate = fscanf(fidIQ, '%d', 1);
end
% fetch freq_offset
stat = fseekStr(fidIQ, '"FreqOffset" Value="');
if stat == -1
disp 'ERROR: sample rate could not be found in file';
freq_offset = 0;
else
freq_offset = fscanf(fidIQ, '%e', 1);
end
freq_offset
%find data section
stat = fseekStr(fidIQ, '<Data>');
if stat == -1
disp 'ERROR: data could not be found in file';
fclose(fidIQ);
return;
end
DataIQ = fread(fidIQ,samples*2,'bit24');
Data = DataIQ(1:2:end) + j*DataIQ(2:2:end);
fclose(fidIQ);
len = length(Data);
%t = [0:len-1]/samp_rate;
freqs = [-len/2:len/2-1]*samp_rate/len;
f = fftshift(20*log10(abs(fft(Data)+eps)));
f = f-max(f);
plot(freqs,f);
length(Data)
function status = fseekStr(fid, str)
% read from fid until we find str
% used to extract values from the XML-based .wcap files