Technical data

276 Agilent Signal Generators Programming Guide
Creating and Downloading Waveform Files
Programming Examples
iwrite(id, iqbuffer, bytesToSend, 0, 0);
iwrite(id, “\n”, 1, 1, 0);
printf(“Loaded FILE2 using the E4438C, E8267C and E8267D format\n”);
return 0;
}
Calculating the RMS Voltage for a Waveform Programming Using C++
This example calculates the RMS voltage value of a waveform segment stored as 16- bit alternating I/Q
twos complement DAC values. Refer to the User’s Guide. On the Documentation CD, this example is
named: “calculate_rms_data_c++.txt.”
NOTE For a short the value must be a 16 bit quantity.
For waveforms of 4 Gsa or more, samples must be an int64.
Internally, the MXG ignores two or more zeros in a row when calculating RMS voltage values.
There is no interface version of this example in the Programming Examples chapter.
#include <math.h>
#ifndef WIN32
typedef long long int int64;
typedef long long unsigned uint64;
#else // WIN32
typedef __int64 int64;
typedef unsigned __int64 uint64;
#endif // WIN32
static const int NUM_DAC_BITS=16;
static const int DAC_MAX=(1 << NUM_DAC_BITS);
//----------------------------------------------------------------------------
// calculates the rms of a chunk of a waveform stored as 16-bit alternating
// I/Q twos complement DAC values.
// NOTE: short must be a 16 bit quantity.
// Also NOTE: For 4Gsa or more, samples must be an int64.
double
calcRmsWaveformSegment(const signed short* iq_data, unsigned samples)
{
// a double cannot hold the full number accurately for very long waveforms
// This type can handle up to (but not including) 8Gsa.
uint64 sum_of_squares_accum = 0;
int ival;
int qval;