Sine-Wave example

% open connection to fg and os, setup function generator
instr_clear();
instr_connect();
clear_errors();
fg_setup;
fprintf(os,'AUTOSCALE');
fprintf(os,'TIMEBASE:SCALE %gus',200);
% set oscilloscope for FFT
fprintf(os,'FUNC:OPER FFT');
fprintf(os,'FUNC:SOURCE CHAN1');
fprintf(os,'CHAN1:DISPLAY OFF');
fprintf(os,'FUNC:DISPLAY 1');
% set FFT parameters
span =  50e3;
center = 25e3;
fprintf(os,'FUNC:SPAN %g',span);
fprintf(os,'FUNC:CENTER %g',center);
scale = 5;
fprintf(os,'FUNC:SCALE %g',scale);
offset = -15;
fprintf(os,'FUNC:OFFSET %g',offset);

% vary input voltage, ask user to mark peaks.
v = [2 3 4 1 0.5 ];
y1p = zeros(size(v));
vc = zeros(size(v));
for k = 1:length(v)
    % set function generator
    vpp = v(k);
    fprintf(fg,'VOLT %g',vpp);
    % set cursors
    fprintf(os,'MARKER:MODE MAN');
    fprintf(os,'MARKER:X1P %g',freq);
    disp('set Y position');
    % wait for user to move Y1 marker
    pause();
    fprintf(os,'MARKER:Y1P?');
    y1p(k) = fscanf(os,'%g');
    vc(k) = 20*log10(0.5*vpp/sqrt(2));
    fprintf('%8g %8g %8g\n',vpp,y1p(k),vc(k));
end
fprintf('%10s%10s%10s\n','vpp','measure','calc');
disp(sort([v' y1p' vc']));
save sine.mat v y1p vc;

Here are some typical results:

       Vpp   calc dB   meas dB
    0.5000  -15.0515  -14.8400
    1.0000   -9.0309   -8.7500
    2.0000   -3.0103   -3.1300
    3.0000    0.5115    0.6300
    4.0000    3.0103    2.9700

These results suggest (to me at least) that the formula used to calculate the dB value must be the same formula used by the oscillosope.