DPO MATLAB ICT Get Waveform 3

本文介绍了如何使用MATLAB与TektronixDPO4104oscilloscope进行交互,通过VISA-USB接口获取波形数据,设置X-Y轴范围,并展示如何进行数据处理和绘制波形图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

%% DPO MATLAB ICT Get Waveform 3

% Date: 04-08-2010

% ==================

% Demonstrate how to retrieve sample data from a DPO series oscilloscope and scale X & Y into voltage and time.

%

% TESTED & DEVELOPED

% ==================

% Microsoft Windows XP SP2

% TekVISA v3.3.2.7

% MATLAB Version 7.6.0.324 (R2008a)

% Instrument Control Toolbox Version 2.6

% USB (TekUSB.sys v0.0.0.25)

% DPO4104 FW v2.28

% ==================

% Find a VISA-USB object.

obj1 = instrfind('Type', 'visa-usb', 'RsrcName', 'USB0::0x0699::0x03A3::C020161::0::INSTR', 'Tag', '');

% Create the VISA-USB object if it does not exist

% otherwise use the object that was found.

if isempty(obj1)

obj1 = visa('NI', 'USB0::0x0699::0x03A3::C020161::0::INSTR');

else

fclose(obj1);

obj1 = obj1(1);

end

% Connect to instrument object, obj1.

fopen(obj1);

%% Disconnect and Clean Up

% The following code has been automatically generated to ensure that any

% object manipulated in TMTOOL has been properly disposed when executed

% as part of a function or script.

% Disconnect all objects.

fclose(obj1);

% Clean up all objects.

delete(obj1);

clear obj1;

%% variables

visa_brand = 'ni';

visa_address = 'USB0::0x0699::0x03A3::C020161::0::INSTR';

buffer = 2000 * 1024;

%% Code

dpo = visa(visa_brand,visa_address,'InputBufferSize',buffer,'OutputBufferSize',buffer);

fopen(dpo);

query(dpo,'*idn?;')

query(dpo,'*esr?;')

if ans ~= '0'

query(dpo,':allev?;')

end

% get scope state

head = query(dpo,':head?;');

head = head(end-1);

%verb = query(dpo,':verb?;');

%verb = verb(end-1);

fwrite(dpo,':head 0;*cls;');

[lrn_str bytes warning] = query(dpo,'*lrn?;');

%save dpo4k_spi.lrn lrn_str -ASCII %doesn't work, numerical data

fid = fopen('dpo4k_spi.lrn', 'wt');

fprintf(fid,lrn_str,'%s')

fclose(fid);

% activate desired channel

query(dpo,':data:source ch2;:data?;') % set source before wfmo

query(dpo,':wfmo?;')

query(dpo,':data?;')

%query(dpo,':data:stop max;:data:stop?;')

reco = query(dpo,':hor:reco?;'); %find record lenght

fwrite(dpo,[':data:start 1;stop ' reco(1:end-1) ';']);

% retrieve vertical scaling informaiton

yof = query(dpo,':wfmo:yof?;','%s','%E');

ymu = query(dpo,':wfmo:ymu?;','%s','%E');

yze = query(dpo,':wfmo:yze?;','%s','%E');

% retrieve horizontal scaling information

nrp = query(dpo,':wfmo:nr_p?;','%s','%E');

xin = query(dpo,':wfmo:xin?;','%s','%E');

xze = query(dpo,':wfmo:xze?;','%s','%E');

% get string values

details = query(dpo,':wfmo:wfi?;');

% get time from trigger

% retrieve raw waveform data

fwrite(dpo,':curve?;');

wave = int8(binblockread(dpo,'int8'));

scaled_wave = (double(wave)-yof).*ymu+yze;

scaled_time = linspace(xze,xze+(xin*nrp),nrp);

%% create figure

wfmgraph = stairs(scaled_time,scaled_wave);

set(1,'NumberTitle','off','Name','my wave');

title(details);

xlabel('time (s)');

ylabel('voltage (v)');

%ylim([min(scaled_wave) max(scaled_wave)]); delete(maxline,minline);

xlim([min(scaled_time) max(scaled_time)]);

% trigger point annotation

trigline = line([0 0],[max(scaled_wave) min(scaled_wave)],[0 0],'Color','red','LineStyle',':');

% max annotation

maxline = line([min(scaled_time) max(scaled_time)],[max(scaled_wave) max(scaled_wave)],[0 0],'Color','cyan','LineStyle','--');

% min annotation

minline = line([min(scaled_time) max(scaled_time)],[min(scaled_wave) min(scaled_wave)],[0 0],'Color','cyan','LineStyle','--');

% scaled grid

grid on

delete(1)

%% return to scope_land

% return scope state

fwrite(dpo,lrn_str)

if head == '1'

fwrite(dpo,[':head ' head ';:verb ' verb ';']);

end

%% reset

fclose(instrfindall)

delete(instrfindall)

clear all

clc

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

happy_baymax

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值