EasyManua.ls Logo

HP ESA-E Series - Page 140

HP ESA-E Series
398 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
3-76 Chapter3
Programming Examples
Measuring Harmonic Distortion (HP-IB)
/*Take a sweep and wait for the sweep completion*/
TakeSweep();
/*Query and read the Marker Amplitude in volts and
store the result in the Harmonic_V(*) array.*/
viQueryf(viESA,"CALC:MARK:Y?\n","%1f", &fHarmV[i]);
/*Change the amplitude units to DBM */
viPrintf(viESA,"UNIT:POW DBM; \n");
/*Take a sweep and wait for the sweep completion*/
TakeSweep();
/* Read the marker amplitude */
viQueryf(viESA,"CALC:MARK:Y?\n","%1f", &fHarmDbm[i]);
}
/*Sum the square of each element in the Harmonic_V(*)
array. Then calculate the relative amplitude of each
harmonic relative to the fundamental */
for (lNum=2;lNum<=lMaxHarmonic;lNum++)
{
dSumSquare= dSumSquare + (pow (double(fHarmV[i])
,2.0));
/* Relative Amplitude */
fRelAmptd[lNum] = fHarmDbm[lNum] - fFundaAmptdDbm ;
}
/*Calculate the total harmonic distortion by dividing
the square root of the sum of the squares (dSumSquare) by
the fundamental amplitude in volts (dFundaAmptdV).Multiply
this value by 100 to obtain a result in percent*/
dPrcntDistort = ((sqrt(double (dSumSquare)))
/dFundaAmptdV) *100 ;
/*Fundamental amplitude in dBm */
printf("Fundamental Amplitude: %lf dB
\n",fFundaAmptdDbm);
/*Fundamental Frequency in MHz*/
printf("Fundamental Frequency is: %lf MHz
\n",dFundamental/10e5);
/*Relative amplitude of each harmonic in dBc*/
for (lNum=2;lNum<=lMaxHarmonic;lNum++)
printf("Relative amplitude of Harmonic[%d]: %lf dBc

Table of Contents