296 Keysight Signal Generators Programming Guide
Creating and Downloading Waveform Files 
Programming Examples 
end
function [data, rms] = FormatWaveform( iqWave )
    % Scale the waveform to DAC values
    [a,b] = size(iqWave);
    if a>b
        iqWave = iqWave';
    end
    maxV = max(abs([real(iqWave) imag(iqWave)]));
    if maxV==0 maxV=1; end  % Prevent divide by zero
    scale = 32767/maxV;
    iqWave = round( scale*iqWave );
    % Calcurate waveform RMS
    rms = sqrt(mean(abs(iqWave).^2)) / 32767;
    % account for pulse duty cycle
    pw = sum(abs(iqWave)>0);
    dutyCycle = pw/length(iqWave);
    rms = rms/dutyCycle;
 
    % Interlace the I & Q vectors
    data = [real(iqWave);imag(iqWave)];
    data = data(:)';
 
end
function mkr = FormatMarkers( markers )
% The markers are placed in the 4 LSBs of a byte
% in this order M4 M3 M2 M1
    [c,d] = size(markers);
    if c>d
        markers = markers';
        [c,d] = size(markers);    
    end
    mkr = (markers(1,:)~=0);
    if c>1
        mkr = mkr + 2*(markers(2,:)~=0);
    end
    if c>2
        mkr = mkr + 4*(markers(3,:)~=0);
    end
    if c>3