166 Chapter 3
Programming Examples
Measuring Harmonic Distortion (GPIB)
viPrintf(viESA,"INIT:IMM;*WAI\n");
/*Perform a peak search */
viPrintf(viESA,"CALC:MARK:MAX \n");
/*increase timeout to 60 sec*/
viSetAttribute(viESA,VI_ATTR_TMO_VALUE,60000);
/*Perform activate signal track */
viPrintf(viESA,"CALC:MARK:TRCK:STAT ON \n");
/*Take a sweep and wait for the sweep completion*/
TakeSweep();
/*Perform narrow span and wait */
viPrintf(viESA,"SENS:FREQ:SPAN 10e4 \n");
/*Take a sweep and wait for the sweep completion*/
TakeSweep();
/*De activate the signal track */
viPrintf(viESA,"CALC:MARK:TRCK:STAT OFF \n");
/*Reset timeout to 3 sec*/
viSetAttribute(viESA,VI_ATTR_TMO_VALUE,3000);
/*Set units to DBM*/
viPrintf(viESA,"UNIT:POW DBM \n");
/*Perform a peak search */
viPrintf(viESA,"CALC:MARK:MAX \n");
/*Read the marker amplitude, this is the fundamental amplitude
in dBm */
viQueryf(viESA,"CALC:MARK:Y?\n","%1f", &fFundaAmptdDbm);
/*Change the amplitude units to Volts */
viPrintf(viESA,"UNIT:POW V \n");
/*Read the marker amplitude in volts, This is the fundamental amplitude
in Volts (necessary for the THD calculation).*/
viQueryf(viESA,"CALC:MARK:Y?\n","%lf",&dFundaAmptdV);
/*Read the marker frequency. */
viQueryf(viESA,"CALC:MARK:X? \n","%lf",&dMarkerFreq);
dFundamental = dMarkerFreq;