IC toolbox, improve speed reading data from spectrum analyzer through the LAN

4 views (last 30 days)
Mike
Mike on 29 Jun 2014
Answered: Vinod on 7 Jul 2014
I have to get the power spectrum and frequencies off the spectrum analyzer as fast as possible. I wondered if there was a more efficient way to implement this code? The profiler suggests changing the structure of the fread statements, but I am implementing that change wrong or it doesn't work with this toolbox. You can see the implementation suggested commented out. Thanks
% Assign a resource for the Spec An fsv = visa('NI','TCPIP::192.168.1.8::HISLIP'); % % set(fsv,'EOSMode','read&write'); % EOI line when the line feed character is written to the instrument
set(fsv,'EOSCharCode','LF'); %read operations when the line feed character is read from the instrument % fsv.inputbuffersize = 200000; % 201*8+100; fsv.timeout = 60; % set I/O timeout to 20 sec, if not long enough, as SpecAn averages, % can take to long and timeout the system. %
% Lets get-er started fopen(fsv); %Open communication
% Spectrum analyzer control
fprintf(fsv,':FORM:DATA REAL,32'); % sets trace data format
fprintf(fsv, 'TRAC? TRACE1');
% fprintf(zva,'SYST:COMM:GPIB:RTER EOI ');
% fread(fsv,1,'char'); % read and discard first character (#)
char(fread(fsv,1)); % read and discard first character (#)
% read digit indicating number of digits in byte count
%ndig = str2double(fread(fsv,1,'char'));
ndig = str2double(char(fread(fsv,1)));
%read byte count and convert to number
nbytes = str2double(char(fread(fsv,ndig))');
%mike = fread(fsv,ndig);
%nbytes = str2double((fread(fsv,ndig,'char'))');
noisePowerSpectrum = fread(fsv,nbytes/4,'single');
% Get the corresponding frequencies
fprintf(fsv,':FORM:DATA REAL,32'); % sets trace data format
fprintf(fsv, 'TRAC:X? TRACE1');
% fprintf(zva,'SYST:COMM:GPIB:RTER EOI ');
char(fread(fsv,1)); % read and discard first character (#)
% fread(fsv,1,'char'); % read and discard first character (#)
% read digit indicating number of digits in byte count
ndig = str2double(char(fread(fsv,1)));
% ndig = str2double((fread(fsv,1,'char')));
%read byte count and convert to number
nbytes = str2double(char(fread(fsv,ndig))');
% nbytes = str2double((fread(fsv,ndig,'char'))');
spectrumFrequencies = fread(fsv,nbytes/4,'single');
fclose(fsv);

Answers (1)

Vinod
Vinod on 7 Jul 2014
I strongly suspect that the bottleneck here is not your code, but how fast your instrument is making the measurement and putting the data on the bus. If you open up the IO Trace tool and look at the timestamps, you will notice that the time is actually being spent by the instrument making the measurement.
Also, it looks like you are reading back binary blocks. Have you looked to use the BINBLOCKREAD function? That may speed up the logic you have after the fprintf(fsv, 'TRAC? TRACE1'); line of code.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!