Tektronix Technical Forums are maintained by community involvement. Feel free to post questions or respond to questions by other members. Should you require a time-sensitive answer, please contact your local Tektronix support center here.

AFG3000 Matlab Load and Output 2 Separate Waveforms

Post Reply

AFG3000 Matlab Load and Output 2 Separate Waveforms

Post by tekzilla » June 17th, 2014, 9:46 am

This code loads two separate waveforms from a USB flash drive into the AFG and then outputs them. The two waveforms were made using ArbExpress in .TFW format and are located in the top directory of the flash drive. ArbExpress can be downloaded here: http://www.tek.com/signal-generator/afg ... 1-software

Code: Select all

% Date: 6/16/14
% Tested on a 64-bit Windows 7 computer
% using TekVISA 4.0.0 and Matlab 2013a
% with the Matlab Instrument Control Toolbox
% Program: AFG3000 Dual Channel Arb Waveform Load and Output
% This program configures amplitude and frequency for both channels,
% loads two separate waveforms into the AFG, and outputs them
% on Channel 1 and Channel 2, respectively.

%% Set up TekVISA
% Specify VISA brand, instrument address, and buffer. Open instrument
visa_brand = 'tek';
visa_address = 'USB::0x0699::0x0345::C010255::INSTR';
buffer = 50 * 1024;
instrument = visa(visa_brand,visa_address,'InputBuffer',buffer,...

% Define waveform file names, note the inclusion of double-quotes
% INSIDE the string
%Waveform name includes # of points for the sake of clarity
wfm1name = '"Cardiac_10k.TFW"';
wfm2name = '"Sinc_10k.TFW"';

ID = query(instrument,'*IDN?');         %Query instrument identifier.
disp(ID);                               %Display instrument identifier
fwrite(instrument,'*RST');              %Reset the instrument

%% Set up amplitude and frequency
fwrite(instrument,'source1:frequency 5e5');                         %Set channel 1 to output 500 kHz
fwrite(instrument,'source1:voltage:level:immediate:amplitude 2');   %Set channel 1 amplitude to 2Vpp

fwrite(instrument,'source2:frequency 1e6');                         %Set channel 2 to output 1 MHz
fwrite(instrument,'source2:voltage:level:immediate:low -1');        %Set channel 2 high level at 1V
fwrite(instrument,'source2:voltage:level:immediate:high 1');        %Set channel 2 low level at -1V

%% Load TFW files into channels 1 and 2
% Since there is only one memory location into which a user can load a
% waveform, it is necessary to copy each waveform into a separate memory
% location in order to avoid overwriting the first waveform with the second
fprintf(instrument,'mmemory:load:trace ememory, %s', wfm1name); %Load the waveform file into ememory
fwrite(instrument,'data:copy user1, ememory');                  %Copy the waveform from ememory into User1
fwrite(instrument,'source1:function user1');                    %Assign the waveform in User1 to Channel 1

fprintf(instrument,'mmemory:load:trace ememory, %s', wfm2name); %Load the waveform file into ememory
fwrite(instrument,'data:copy user2, ememory');                  %Copy the waveform from ememory into User2
fwrite(instrument,'source2:function user2');                    %Assign the waveform in User2 to Channel 2

fwrite(instrument,'output1:state on');          %Turn on Channel 1 output
fwrite(instrument,'output2:state on');          %Turn on Channel 2 output

%% Disconnect from and close instrument
clear instrument;

Post Reply

Return to “AFG1000/2000/3000 series”

Who is online

Users browsing this forum: No registered users and 3 guests