Azzera filtri
Azzera filtri

Reading from Keysight scope to MATLAB and the integer/byte value limit

53 visualizzazioni (ultimi 30 giorni)
Hello!
I'm having an issue with data acquisition from an oscilloscope. MATLAB captures values that are over the limit of 255 for BYTE format and 65,535 for an unsigned 16-bit integer when using the WORD format, and loops these values back from 0 resulting in a very distorted waveform. I'm using the following code and reading the data using binblockread:
clear all
clc
close all
%%
DSO_S_104A=instrfind('Type', 'visa-usb', 'RsrcName', 'USB0::0x2A8D::0x904A::MY54340109::0::INSTR', 'Tag', '');
DSO_S_104A.InputBufferSize = 350000;
DSO_S_104A.ByteOrder = 'littleEndian';
fopen(DSO_S_104A);
%% SETUP
set(DSO_S_104A, 'Timeout', 0.5);
%Set number of points
fprintf(DSO_S_104A, ':ACQUIRE:POINTS 48000');
% Set sample rate
fprintf(DSO_S_104A, ':ACQUIRE:SRATE 0.5e9');
% Turn interpolation off for faster averaging
fprintf(DSO_S_104A, ':ACQUIRE:INTERPOLATE OFF');
fprintf(DSO_S_104A,'*TRG');
fwrite(DSO_S_104A,'SYSTem:HEADer OFF');
% Specify data from Channel 1
fprintf(DSO_S_104A,':WAVEFORM:SOURCE CHAN1');
fprintf(DSO_S_104A,':WAVEFORM:FORMAT BYTE'); % or WORD
fprintf(DSO_S_104A,':WAVEFORM:BYTEORDER LSBFirst');
fprintf(DSO_S_104A, 'WAVEFORM:STREAMING OFF');
%%
fwrite(DSO_S_104A,sprintf(':WAV:DATA?\n'));
data2 = binblockread(DSO_S_104A); %or data2 = binblockread(DSO_S_104A,'ushort') for WORD format
plot(data2)
end
Is there any way to fix this? I know that for the case of 2pi jumps in phase measurements the "unwrap" command can help, but is there anything for amplitude?
Also, If anybody has any advice how to speed up the data acquisition process from a scope to MATLAB I would welcome any suggestions. Currently to capture one "screen" from the scope it takes MATLAB about 0.04 seconds which remains the same for up to 3-4x the number of points.
I can raise the number of points which puts multiple "scope screens" in one acquisition thus speeding up the proccess (by later cutting each "screen" into a different vector), but it also makes the data processing a bit more difficult.

Risposta accettata

Egor Losev
Egor Losev il 22 Nov 2018
In case anyone ever encounters a similar issue here is how I solved it: In the end the issue was offset voltage on the scope coupled with v/div setings. For some reason zeroed offset was a major problem. I raised the offset voltage (which basically raises the waveform on the scope) until I started capturing the correct waveform, as well as played a bit with the volt/div settings (to a lesser extent). Weird issue.

Più risposte (1)

HeScZe
HeScZe il 12 Dic 2018
Hey Egor Losev,
unfortunately i'vh got the same weird issue. I want to transfer a waveform from the Tek MSO4034B oscilloscope to MATLAB but when i read the waveform with binblockread() i get the same plot like yours. Here is the code:
clc;
clear all;
% Clear MATLAB workspace of any previous instrument connections
instrreset;
% Provide the Resource name of the oscilloscope
visaAddress = 'USB0::0x0699::0x040B::C022621::0::INSTR';
% Create a VISA object and set the |InputBufferSize| to allow for transfer
% of waveform from oscilloscope to MATLAB. Tek VISA needs to be installed.
myScope = visa('NI', visaAddress, 'InputBufferSize', 8000000);
% Set configuration for scope
myScope.ByteOrder = 'littleEndian';
fopen(myScope); % Open the connection to the oscilloscope
fprintf(myScope, ':HEADer 1'); % Turn headers off, this makes parsing easier
fprintf(myScope, 'ACQuire:MODe HIRes'); % High Resolution
fprintf(myScope, ':DATa:SOUrce CH1'); % Channel 1
fprintf(myScope, ':DATa:STARt 1'); % RecordLength
fprintf(myScope, ':DATa:STOP 10000');
yOffset = query(myScope, 'WFMO:YOFF?'); % Read YOFFSET to calculate the vertical values
verticalScale = query(myScope,'WFMOUTPRE:YMULT?'); % Read YMULT to calculate the vertical values
fprintf(myScope, 'DATA:ENCDG RIBINARY;WIDTH 1'); % Request 8 bit binary data on the CURVE query
fprintf(myScope, 'ACQuire:STATE RUN'); % Run Acqusition
pause(5);
fprintf(myScope, 'ACQuire:STATE STOP');
out = query(myScope, ':WFMOutpre?'); % Show output config
fprintf(myScope, ':HEADer 0');
% Request the CURVE
fwrite(myScope, 'CURVE?');
pause(3)
%% Read the captured data
data = binblockread(myScope);
% Clean up Close the connection
fclose(myScope);
% Clear the variable
clear myScope;
% Plot the acquired data and add axis labels
figure;
plot(data);
xlabel('Sample Index');
ylabel('Volts');
title('Waveform');
grid on;
I want to aquire the data as double values but wheter i use (binblockread(myScope, 'double') or without it i get the high amplitude.
How excactly did you change your offset? Did you increase the offset at the scope or with a MATLAB command?
Thanks, have a nice day
HeScZe
  1 Commento
Egor Losev
Egor Losev il 18 Dic 2018
Modificato: Egor Losev il 18 Dic 2018
Hello!
I changed it on the scope. I simply ran the data read continuously with plot and adjusted the offset voltage on the scope untill I got a clean waveform.

Accedi per commentare.

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by