I have been trying to load an arbitrary waveform in function generator using MATLAB (visa). However, I dont obtain the waveform that I have designed. The code used is given below. I initially tested the code with a simple sine wave of 1Hz. However, the wave generated is of very much higher frequency (of the order of kHz). I suspect it is due to much lower sampling frequency. The 50Mbps sampling rate of the function generator creates a huge amount of data, that cannot be handled by MAtlab. Also, I ultimately want to create a chirp with 1000 sec sweep time. For that, I need to *reduce the sampling rate of the generator* .Please provide me the commands for the same. The codes I used is given below-
fgen = visa('AGILENT','USB0::0x0957::0x0407::MY44048510::0::INSTR');
set (fgen,'OutputBufferSize',100000);
fopen(fgen);
%Query Idendity string and report
fprintf (fgen, '*IDN?');
idn = fscanf (fgen);
fprintf (idn)
fprintf ('\n\n')
%Clear and reset instrument
fprintf (fgen, '*RST');
fprintf (fgen, '*CLS');
% Create arb waveform
fprintf('Generating Waveform...\n\n')
sRate = 100;
ch = [];
for t = 0:1/sRate:10
c = sin(t);
y = num2str(c);
s5 = sprintf(', %s',y);
ch = [ch s5];
end
%combine all of the strings
% s = [rise width fall low];
s = [ch];
% combine string of data with scpi command
arbstring =sprintf('DATA VOLATILE %s', s);
%Send Command to set the desired configuration
fprintf('Downloading Waveform...\n\n')
fprintf(fgen, arbstring);
%make instrument wait for data to download before moving on to next
%command set
fprintf(fgen, '*WAI');
fprintf('Download Complete\n\n')
%Set desired configuration.
fprintf(fgen,'VOLT 2'); % set max waveform amplitude to 2 Vpp
fprintf(fgen,'VOLT:OFFSET 0'); % set offset to 0 V
fprintf(fgen,'OUTPUT:LOAD 50'); % set output load to 50 ohms
fprintf(fgen,'FREQ 1'); %set frequency to 1KHz
fprintf(fgen,'DATA:COPY TEST16385, VOLATILE');
fprintf(fgen,'FUNC:USER VOLATILE');
fprintf(fgen,'FUNC:SHAP USER');
%Enable Output
fprintf(fgen,'OUTPUT ON'); % turn on channel 1 output
% Read Error
fprintf(fgen, 'SYST:ERR?');
errorstr = fscanf (fgen);
% error checking
if strncmp (errorstr, '+0,"No error"',13)
errorcheck = 'Arbitrary waveform generated without any error \n';
fprintf (errorcheck)
else
errorcheck = ['Error reported: ', errorstr];
fprintf (errorcheck)
end
%closes the visa session with the function generator
fclose(fgen);
I used the following command to reduce the sampling rate-
sRate = 100;
fprintf(fgen,'SOURCE1:FUNCtion:ARB:SRATe ' num2str(sRate))
The program shows an error at this line
fgen = visa('AGILENT','USB0::0x0957::0x0407::MY44048510::0::INSTR');
set (fgen,'OutputBufferSize',100000);
fopen(fgen);
%Query Idendity string and report
fprintf (fgen, '*IDN?');
idn = fscanf (fgen);
fprintf (idn)
fprintf ('\n\n')
%Clear and reset instrument
fprintf (fgen, '*RST');
fprintf (fgen, '*CLS');
% Create arb waveform
fprintf('Generating Waveform...\n\n')
sRate = 100;
ch = [];
for t = 0:1/sRate:10
c = sin(t);
y = num2str(c);
s5 = sprintf(', %s',y);
ch = [ch s5];
end
%combine all of the strings
% s = [rise width fall low];
s = [ch];
% combine string of data with scpi command
arbstring =sprintf('DATA VOLATILE %s', s);
%Send Command to set the desired configuration
fprintf('Downloading Waveform...\n\n')
fprintf(fgen, arbstring);
%make instrument wait for data to download before moving on to next
%command set
fprintf(fgen, '*WAI');
fprintf('Download Complete\n\n')
%Set desired configuration.
fprintf(fgen,'VOLT 2'); % set max waveform amplitude to 2 Vpp
fprintf(fgen,'VOLT:OFFSET 0'); % set offset to 0 V
fprintf(fgen,'OUTPUT:LOAD 50'); % set output load to 50 ohms
fprintf(fgen,'FREQ 1'); %set frequency to 1KHz
fprintf(fgen,'DATA:COPY TEST16385, VOLATILE');
fprintf(fgen,'FUNC:USER VOLATILE');
fprintf(fgen,'FUNC:SHAP USER');
%Enable Output
fprintf(fgen,'OUTPUT ON'); % turn on channel 1 output
% Read Error
fprintf(fgen, 'SYST:ERR?');
errorstr = fscanf (fgen);
% error checking
if strncmp (errorstr, '+0,"No error"',13)
errorcheck = 'Arbitrary waveform generated without any error \n';
fprintf (errorcheck)
else
errorcheck = ['Error reported: ', errorstr];
fprintf (errorcheck)
end
%closes the visa session with the function generator
fclose(fgen);
I used the following command to reduce the sampling rate-
sRate = 100;
fprintf(fgen,'SOURCE1:FUNCtion:ARB:SRATe ' num2str(sRate))
The program shows an error at this line
However you can change the Frequency/Period of the waveform. You just tell the box what frequency/period you want for the waveform and it will skip/repeat points using a patented formula to achieve that effective frequency/period.
Example FREQ 10, will output the waveform at 10Hz
The 33500/33600 generators use a different method (trueform) which gives you more of a point per clock type behavior.